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 2D20D1382C5 for ; Sun, 29 Apr 2018 04:38:24 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 88D09E081E; Sun, 29 Apr 2018 04:38:23 +0000 (UTC) Received: from smtp.gentoo.org (smtp.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 4FF90E081E for ; Sun, 29 Apr 2018 04:38:23 +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 1D7EB335C9B for ; Sun, 29 Apr 2018 04:38:22 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 4D11F298 for ; Sun, 29 Apr 2018 04:38:20 +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: <1524975716.bca4f6a58512471cdf1caf644cee9858ca3bd1eb.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/_emerge/ X-VCS-Repository: proj/portage X-VCS-Files: pym/_emerge/AbstractEbuildProcess.py pym/_emerge/AsynchronousTask.py X-VCS-Directories: pym/_emerge/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: bca4f6a58512471cdf1caf644cee9858ca3bd1eb X-VCS-Branch: master Date: Sun, 29 Apr 2018 04:38:20 +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-Archives-Salt: 1fd5d8ca-a462-4a85-8332-bbfbd820baf0 X-Archives-Hash: ac5b5cb3dae978412ea15fffbbccd632 commit: bca4f6a58512471cdf1caf644cee9858ca3bd1eb Author: Zac Medico gentoo org> AuthorDate: Thu Apr 26 09:51:43 2018 +0000 Commit: Zac Medico gentoo org> CommitDate: Sun Apr 29 04:21:56 2018 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=bca4f6a5 AsynchronousTask: disable event loop recursion (bug 653856) Make the wait() and _async_wait() methods raise InvalidStateError when the event loop is running and the returncode is not available, since these cases would trigger event loop recursion. There are no known remaining cases that cause event loop recursion via wait() and _async_wait(), and this patch protects against changes that would accidentally re-introduce event loop recursion. Since the wait() method now raises InvalidStateError in cases where it previously would have called the _wait() method, this patch makes it possible to remove the _wait() method implementations from all subclasses of AsynchronousTask. Subclasses that used the _wait() method to perform cleanup now use the _async_wait() method instead. Bug: https://bugs.gentoo.org/653856 pym/_emerge/AbstractEbuildProcess.py | 5 ++++- pym/_emerge/AsynchronousTask.py | 24 ++++++++++++++---------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/pym/_emerge/AbstractEbuildProcess.py b/pym/_emerge/AbstractEbuildProcess.py index 1012ce166..b10aa4bfa 100644 --- a/pym/_emerge/AbstractEbuildProcess.py +++ b/pym/_emerge/AbstractEbuildProcess.py @@ -1,4 +1,4 @@ -# Copyright 1999-2012 Gentoo Foundation +# Copyright 1999-2018 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import errno @@ -18,6 +18,7 @@ from portage.localization import _ from portage.package.ebuild._ipc.ExitCommand import ExitCommand from portage.package.ebuild._ipc.QueryCommand import QueryCommand from portage import shutil, os +from portage.util.futures import asyncio from portage.util._pty import _create_pty_or_pipe from portage.util import apply_secpass_permissions @@ -420,6 +421,8 @@ class AbstractEbuildProcess(SpawnProcess): if self._build_dir is None: SpawnProcess._async_wait(self) elif self._build_dir_unlock is None: + if self.returncode is None: + raise asyncio.InvalidStateError('Result is not ready.') self._async_unlock_builddir(returncode=self.returncode) def _async_unlock_builddir(self, returncode=None): diff --git a/pym/_emerge/AsynchronousTask.py b/pym/_emerge/AsynchronousTask.py index 9d8df7f5e..246895d71 100644 --- a/pym/_emerge/AsynchronousTask.py +++ b/pym/_emerge/AsynchronousTask.py @@ -1,9 +1,10 @@ -# Copyright 1999-2012 Gentoo Foundation +# Copyright 1999-2018 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import signal from portage import os +from portage.util.futures import asyncio from portage.util.SlotObject import SlotObject class AsynchronousTask(SlotObject): @@ -17,8 +18,7 @@ class AsynchronousTask(SlotObject): """ __slots__ = ("background", "cancelled", "returncode", "scheduler") + \ - ("_exit_listeners", "_exit_listener_stack", "_start_listeners", - "_waiting") + ("_exit_listeners", "_exit_listener_stack", "_start_listeners") _cancelled_returncode = - signal.SIGINT @@ -68,15 +68,19 @@ class AsynchronousTask(SlotObject): def wait(self): """ - Deprecated. Use async_wait() instead. + Wait for the returncode attribute to become ready, and return + it. If the returncode is not ready and the event loop is already + running, then the async_wait() method should be used instead of + wait(), because wait() will raise asyncio.InvalidStateError in + this case. + + @rtype: int + @returns: the value of self.returncode """ if self.returncode is None: - if not self._waiting: - self._waiting = True - try: - self._wait() - finally: - self._waiting = False + if self.scheduler.is_running(): + raise asyncio.InvalidStateError('Result is not ready.') + self.scheduler.run_until_complete(self.async_wait()) self._wait_hook() return self.returncode