aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2021-03-06 19:03:40 -0800
committerZac Medico <zmedico@gentoo.org>2021-03-06 21:12:48 -0800
commit15049a041909f85b02a52f5b1938c6dd4171c9e3 (patch)
treebaf25056a4e25060a5a2a3e842e071bba6d840b6
parentRemove unused PollSelectAdapter and PollConstants classes (diff)
downloadportage-15049a041909f85b02a52f5b1938c6dd4171c9e3.tar.gz
portage-15049a041909f85b02a52f5b1938c6dd4171c9e3.tar.bz2
portage-15049a041909f85b02a52f5b1938c6dd4171c9e3.zip
Removed unused portage.util.futures._asyncio.tasks
Signed-off-by: Zac Medico <zmedico@gentoo.org>
-rw-r--r--lib/portage/util/futures/_asyncio/__init__.py46
-rw-r--r--lib/portage/util/futures/_asyncio/tasks.py96
2 files changed, 19 insertions, 123 deletions
diff --git a/lib/portage/util/futures/_asyncio/__init__.py b/lib/portage/util/futures/_asyncio/__init__.py
index 207e7205d..4643697e0 100644
--- a/lib/portage/util/futures/_asyncio/__init__.py
+++ b/lib/portage/util/futures/_asyncio/__init__.py
@@ -25,7 +25,16 @@ import types
import weakref
import asyncio as _real_asyncio
-from asyncio.subprocess import Process
+# pylint: disable=redefined-builtin
+from asyncio import (
+ ALL_COMPLETED,
+ CancelledError,
+ FIRST_COMPLETED,
+ FIRST_EXCEPTION,
+ Future,
+ InvalidStateError,
+ TimeoutError,
+)
try:
import threading
@@ -38,20 +47,6 @@ portage.proxy.lazyimport.lazyimport(globals(),
'portage.util.futures:compat_coroutine@_compat_coroutine',
)
from portage.util._eventloop.asyncio_event_loop import AsyncioEventLoop as _AsyncioEventLoop
-# pylint: disable=redefined-builtin
-from portage.util.futures.futures import (
- CancelledError,
- Future,
- InvalidStateError,
- TimeoutError,
-)
-# pylint: enable=redefined-builtin
-from portage.util.futures._asyncio.tasks import (
- ALL_COMPLETED,
- FIRST_COMPLETED,
- FIRST_EXCEPTION,
- wait,
-)
_lock = threading.Lock()
@@ -131,20 +126,17 @@ def create_subprocess_exec(*args, **kwargs):
# Python 3.4 and later implement PEP 446, which makes newly
# created file descriptors non-inheritable by default.
kwargs.setdefault('close_fds', False)
- if isinstance(loop._asyncio_wrapper, _AsyncioEventLoop):
- # Use the real asyncio create_subprocess_exec (loop argument
- # is deprecated since since Python 3.8).
- return _real_asyncio.create_subprocess_exec(*args, **kwargs)
-
- result = loop.create_future()
+ # Use the real asyncio create_subprocess_exec (loop argument
+ # is deprecated since since Python 3.8).
+ return ensure_future(_real_asyncio.create_subprocess_exec(*args, **kwargs), loop=loop)
- result.set_result(Process(subprocess.Popen(
- args,
- stdin=kwargs.pop('stdin', None),
- stdout=kwargs.pop('stdout', None),
- stderr=kwargs.pop('stderr', None), **kwargs), loop))
- return result
+def wait(futures, loop=None, timeout=None, return_when=ALL_COMPLETED):
+ """
+ Wraps asyncio.wait() and omits the loop argument which is not
+ supported since python 3.10.
+ """
+ return _real_asyncio.wait(futures, timeout=timeout, return_when=return_when)
def iscoroutinefunction(func):
diff --git a/lib/portage/util/futures/_asyncio/tasks.py b/lib/portage/util/futures/_asyncio/tasks.py
deleted file mode 100644
index c9db3146e..000000000
--- a/lib/portage/util/futures/_asyncio/tasks.py
+++ /dev/null
@@ -1,96 +0,0 @@
-# Copyright 2018-2020 Gentoo Authors
-# Distributed under the terms of the GNU General Public License v2
-
-___all___ = (
- 'ALL_COMPLETED',
- 'FIRST_COMPLETED',
- 'FIRST_EXCEPTION',
- 'wait',
-)
-
-from asyncio import ALL_COMPLETED, FIRST_COMPLETED, FIRST_EXCEPTION
-
-import portage
-portage.proxy.lazyimport.lazyimport(globals(),
- 'portage.util.futures:asyncio',
-)
-
-def wait(futures, loop=None, timeout=None, return_when=ALL_COMPLETED):
- """
- Use portage's internal EventLoop to emulate asyncio.wait:
- https://docs.python.org/3/library/asyncio-task.html#asyncio.wait
-
- @param futures: futures to wait for
- @type futures: asyncio.Future (or compatible)
- @param timeout: number of seconds to wait (wait indefinitely if
- not specified)
- @type timeout: int or float
- @param return_when: indicates when this function should return, must
- be one of the constants ALL_COMPLETED, FIRST_COMPLETED, or
- FIRST_EXCEPTION (default is ALL_COMPLETED)
- @type return_when: object
- @param loop: event loop
- @type loop: EventLoop
- @return: tuple of (done, pending).
- @rtype: asyncio.Future (or compatible)
- """
- loop = asyncio._wrap_loop(loop)
- result_future = loop.create_future()
- _Waiter(futures, timeout, return_when, result_future, loop)
- return result_future
-
-
-class _Waiter:
- def __init__(self, futures, timeout, return_when, result_future, loop):
- self._futures = futures
- self._completed = set()
- self._exceptions = set()
- self._return_when = return_when
- self._result_future = result_future
- self._loop = loop
- self._ready = False
- self._timeout = None
- result_future.add_done_callback(self._cancel_callback)
- for future in self._futures:
- future.add_done_callback(self._done_callback)
- if timeout is not None:
- self._timeout = loop.call_later(timeout, self._timeout_callback)
-
- def _cancel_callback(self, future):
- if future.cancelled():
- self._ready_callback()
-
- def _timeout_callback(self):
- if not self._ready:
- self._ready = True
- self._ready_callback()
-
- def _done_callback(self, future):
- if future.cancelled() or future.exception() is None:
- self._completed.add(id(future))
- else:
- self._exceptions.add(id(future))
- if not self._ready and (
- (self._return_when is FIRST_COMPLETED and self._completed) or
- (self._return_when is FIRST_EXCEPTION and self._exceptions) or
- (len(self._futures) == len(self._completed) + len(self._exceptions))):
- self._ready = True
- # use call_soon in case multiple callbacks complete in quick succession
- self._loop.call_soon(self._ready_callback)
-
- def _ready_callback(self):
- if self._timeout is not None:
- self._timeout.cancel()
- self._timeout = None
- if self._result_future.cancelled():
- return
- done = []
- pending = []
- done_ids = self._completed.union(self._exceptions)
- for future in self._futures:
- if id(future) in done_ids:
- done.append(future)
- else:
- pending.append(future)
- future.remove_done_callback(self._done_callback)
- self._result_future.set_result((set(done), set(pending)))