public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/util/futures/_asyncio/
Date: Sun,  7 Mar 2021 05:28:47 +0000 (UTC)	[thread overview]
Message-ID: <1615093968.15049a041909f85b02a52f5b1938c6dd4171c9e3.zmedico@gentoo> (raw)

commit:     15049a041909f85b02a52f5b1938c6dd4171c9e3
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Sun Mar  7 03:03:40 2021 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> 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 <zmedico <AT> 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)))


             reply	other threads:[~2021-03-07  5:28 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-07  5:28 Zac Medico [this message]
  -- strict thread matches above, loose matches on Subject: below --
2024-09-01  7:02 [gentoo-commits] proj/portage:master commit in: lib/portage/util/futures/_asyncio/ Zac Medico
2024-09-01  7:02 Zac Medico
2024-09-01  7:02 Zac Medico
2024-08-31 19:20 Zac Medico
2024-08-19 14:49 Zac Medico
2024-08-19 14:49 Zac Medico
2024-02-22 15:36 Zac Medico
2024-02-21 16:00 Zac Medico
2021-09-20  5:36 Zac Medico
2021-03-07 15:17 Zac Medico
2021-03-06  9:14 Zac Medico
2020-12-07  8:41 Zac Medico
2020-08-03 19:30 Zac Medico
2020-06-18 18:06 Zac Medico
2020-02-29  4:33 Zac Medico
2019-10-18  3:43 Zac Medico
2019-05-18 22:25 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1615093968.15049a041909f85b02a52f5b1938c6dd4171c9e3.zmedico@gentoo \
    --to=zmedico@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox