From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id C593A1382C5 for ; Sun, 7 Mar 2021 05:28:53 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 72EF3E084A; Sun, 7 Mar 2021 05:28:51 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id E9AA6E084A for ; Sun, 7 Mar 2021 05:28:50 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 29BAB33BE4D for ; Sun, 7 Mar 2021 05:28:49 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 7538153 for ; Sun, 7 Mar 2021 05:28:47 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1615093968.15049a041909f85b02a52f5b1938c6dd4171c9e3.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/util/futures/_asyncio/ X-VCS-Repository: proj/portage X-VCS-Files: lib/portage/util/futures/_asyncio/__init__.py lib/portage/util/futures/_asyncio/tasks.py X-VCS-Directories: lib/portage/util/futures/_asyncio/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 15049a041909f85b02a52f5b1938c6dd4171c9e3 X-VCS-Branch: master Date: Sun, 7 Mar 2021 05:28:47 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 97d37104-87e2-4e14-9b6b-0fed5354f07a X-Archives-Hash: b16504ac48c8fcbcf9d6ab914b6701b2 commit: 15049a041909f85b02a52f5b1938c6dd4171c9e3 Author: Zac Medico gentoo org> AuthorDate: Sun Mar 7 03:03:40 2021 +0000 Commit: Zac Medico gentoo org> CommitDate: Sun Mar 7 05:12:48 2021 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=15049a04 Removed unused portage.util.futures._asyncio.tasks Signed-off-by: Zac Medico gentoo.org> lib/portage/util/futures/_asyncio/__init__.py | 46 ++++++------- lib/portage/util/futures/_asyncio/tasks.py | 96 --------------------------- 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)))