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 6D35A1382C5 for ; Sat, 6 Mar 2021 09:15:00 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id BB658E0815; Sat, 6 Mar 2021 09:14:59 +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 988D3E0815 for ; Sat, 6 Mar 2021 09:14:59 +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 AADDF340EF8 for ; Sat, 6 Mar 2021 09:14:58 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id D4A6253 for ; Sat, 6 Mar 2021 09:14:56 +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: <1615021613.1e843f853a9afe82d599e6ab09064147ddc1d271.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/process.py X-VCS-Directories: lib/portage/util/futures/_asyncio/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 1e843f853a9afe82d599e6ab09064147ddc1d271 X-VCS-Branch: master Date: Sat, 6 Mar 2021 09:14:56 +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: f2fee85e-4d31-4565-9f56-dc2efd391bb2 X-Archives-Hash: 144d36670ea1113ca6293fcd876b2c80 commit: 1e843f853a9afe82d599e6ab09064147ddc1d271 Author: Matt Turner gentoo org> AuthorDate: Thu Mar 4 19:24:58 2021 +0000 Commit: Zac Medico gentoo org> CommitDate: Sat Mar 6 09:06:53 2021 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=1e843f85 Use asyncio.subprocess.Process directly With no need to support Python 2, we can remove our private implementation. Signed-off-by: Matt Turner gentoo.org> Signed-off-by: Zac Medico gentoo.org> lib/portage/util/futures/_asyncio/__init__.py | 8 +- lib/portage/util/futures/_asyncio/process.py | 116 -------------------------- 2 files changed, 4 insertions(+), 120 deletions(-) diff --git a/lib/portage/util/futures/_asyncio/__init__.py b/lib/portage/util/futures/_asyncio/__init__.py index 5590963f1..207e7205d 100644 --- a/lib/portage/util/futures/_asyncio/__init__.py +++ b/lib/portage/util/futures/_asyncio/__init__.py @@ -25,6 +25,7 @@ import types import weakref import asyncio as _real_asyncio +from asyncio.subprocess import Process try: import threading @@ -45,7 +46,6 @@ from portage.util.futures.futures import ( TimeoutError, ) # pylint: enable=redefined-builtin -from portage.util.futures._asyncio.process import _Process from portage.util.futures._asyncio.tasks import ( ALL_COMPLETED, FIRST_COMPLETED, @@ -124,8 +124,8 @@ def create_subprocess_exec(*args, **kwargs): @type loop: event loop @type kwargs: varies @param kwargs: subprocess.Popen parameters - @rtype: asyncio.Future (or compatible) - @return: subset of asyncio.subprocess.Process interface + @rtype: asyncio.subprocess.Process (or compatible) + @return: asyncio.subprocess.Process interface """ loop = _wrap_loop(kwargs.pop('loop', None)) # Python 3.4 and later implement PEP 446, which makes newly @@ -138,7 +138,7 @@ def create_subprocess_exec(*args, **kwargs): result = loop.create_future() - result.set_result(_Process(subprocess.Popen( + result.set_result(Process(subprocess.Popen( args, stdin=kwargs.pop('stdin', None), stdout=kwargs.pop('stdout', None), diff --git a/lib/portage/util/futures/_asyncio/process.py b/lib/portage/util/futures/_asyncio/process.py deleted file mode 100644 index 275c9031a..000000000 --- a/lib/portage/util/futures/_asyncio/process.py +++ /dev/null @@ -1,116 +0,0 @@ -# Copyright 2018-2020 Gentoo Authors -# Distributed under the terms of the GNU General Public License v2 - -import os - -import portage -portage.proxy.lazyimport.lazyimport(globals(), - 'portage.util.futures:asyncio', - 'portage.util.futures.unix_events:_set_nonblocking', -) -from portage.util.futures._asyncio.streams import _reader, _writer -from portage.util.futures.compat_coroutine import coroutine, coroutine_return - - -class _Process: - """ - Emulate a subset of the asyncio.subprocess.Process interface, - for python2. - """ - def __init__(self, proc, loop): - """ - @param proc: process instance - @type proc: subprocess.Popen - @param loop: asyncio.AbstractEventLoop (or compatible) - @type loop: event loop - """ - self._proc = proc - self._loop = loop - self.terminate = proc.terminate - self.kill = proc.kill - self.send_signal = proc.send_signal - self.pid = proc.pid - self._waiters = [] - loop._asyncio_child_watcher.\ - add_child_handler(self.pid, self._proc_exit) - - @property - def returncode(self): - return self._proc.returncode - - @coroutine - def communicate(self, input=None, loop=None): # pylint: disable=redefined-builtin - """ - Read data from stdout and stderr, until end-of-file is reached. - Wait for process to terminate. - - @param input: stdin content to write - @type input: bytes - @return: tuple (stdout_data, stderr_data) - @rtype: asyncio.Future (or compatible) - """ - loop = asyncio._wrap_loop(loop or self._loop) - futures = [] - for input_file in (self._proc.stdout, self._proc.stderr): - if input_file is None: - future = loop.create_future() - future.set_result(None) - else: - future = _reader(input_file, loop=loop) - futures.append(future) - - writer = None - if input is not None: - if self._proc.stdin is None: - raise TypeError('communicate: expected file or int, got {}'.format(type(self._proc.stdin))) - stdin = self._proc.stdin - stdin = os.fdopen(stdin, 'wb', 0) if isinstance(stdin, int) else stdin - _set_nonblocking(stdin.fileno()) - writer = asyncio.ensure_future(_writer(stdin, input, loop=loop), loop=loop) - writer.add_done_callback(lambda writer: stdin.close()) - - try: - yield asyncio.wait(futures + [self.wait(loop=loop)], loop=loop) - finally: - if writer is not None: - if writer.done(): - # Consume expected exceptions. - try: - writer.result() - except EnvironmentError: - # This is normal if the other end of the pipe was closed. - pass - else: - writer.cancel() - - coroutine_return(tuple(future.result() for future in futures)) - - def wait(self, loop=None): - """ - Wait for child process to terminate. Set and return returncode attribute. - - @return: returncode - @rtype: asyncio.Future (or compatible) - """ - loop = asyncio._wrap_loop(loop or self._loop) - waiter = loop.create_future() - if self.returncode is None: - self._waiters.append(waiter) - waiter.add_done_callback(self._waiter_cancel) - else: - waiter.set_result(self.returncode) - return waiter - - def _waiter_cancel(self, waiter): - if waiter.cancelled(): - try: - self._waiters.remove(waiter) - except ValueError: - pass - - def _proc_exit(self, pid, returncode): - self._proc.returncode = returncode - waiters = self._waiters - self._waiters = [] - for waiter in waiters: - waiter.set_result(returncode)