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 CE5E91382C5 for ; Sat, 21 Apr 2018 18:43:54 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 0CDFDE0870; Sat, 21 Apr 2018 18:43:53 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.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 CB122E0870 for ; Sat, 21 Apr 2018 18:43:52 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (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 5DC30335C49 for ; Sat, 21 Apr 2018 18:43:51 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 4922727C for ; Sat, 21 Apr 2018 18:43:49 +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: <1524336118.87a21a06c8829be6ded41a4c06dcfc19f8ffefc2.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/_emerge/ X-VCS-Repository: proj/portage X-VCS-Files: pym/_emerge/BinpkgFetcher.py X-VCS-Directories: pym/_emerge/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 87a21a06c8829be6ded41a4c06dcfc19f8ffefc2 X-VCS-Branch: master Date: Sat, 21 Apr 2018 18:43:49 +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: 3df33449-f211-4b69-b50d-5219d3b109ea X-Archives-Hash: b67b4c7d8407c9a32301fc2cf5d85e8d commit: 87a21a06c8829be6ded41a4c06dcfc19f8ffefc2 Author: Zac Medico gentoo org> AuthorDate: Sat Apr 21 17:32:49 2018 +0000 Commit: Zac Medico gentoo org> CommitDate: Sat Apr 21 18:41:58 2018 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=87a21a06 BinpkgFetcher: use async_unlock (bug 614108) Convert BinpkgFetcher to a CompositeTask in order to handle asynchronous unlock, and move remaining BinpkgFetcher code to a _BinpkgFetcherProcess class that still inherits SpawnProcess. Bug: https://bugs.gentoo.org/614108 pym/_emerge/BinpkgFetcher.py | 57 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 44 insertions(+), 13 deletions(-) diff --git a/pym/_emerge/BinpkgFetcher.py b/pym/_emerge/BinpkgFetcher.py index c8fd64487..5ca7a45cf 100644 --- a/pym/_emerge/BinpkgFetcher.py +++ b/pym/_emerge/BinpkgFetcher.py @@ -1,7 +1,10 @@ # Copyright 1999-2013 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +import functools + from _emerge.AsynchronousLock import AsynchronousLock +from _emerge.CompositeTask import CompositeTask from _emerge.SpawnProcess import SpawnProcess try: from urllib.parse import urlparse as urllib_parse_urlparse @@ -11,24 +14,56 @@ import stat import sys import portage from portage import os +from portage.util._async.AsyncTaskFuture import AsyncTaskFuture from portage.util._pty import _create_pty_or_pipe if sys.hexversion >= 0x3000000: long = int -class BinpkgFetcher(SpawnProcess): - __slots__ = ("pkg", "pretend", - "locked", "pkg_path", "_lock_obj") +class BinpkgFetcher(CompositeTask): + + __slots__ = ("pkg", "pretend", "logfile", "pkg_path") def __init__(self, **kwargs): - SpawnProcess.__init__(self, **kwargs) + CompositeTask.__init__(self, **kwargs) pkg = self.pkg self.pkg_path = pkg.root_config.trees["bintree"].getname( pkg.cpv) + ".partial" def _start(self): + self._start_task( + _BinpkgFetcherProcess(background=self.background, + logfile=self.logfile, pkg=self.pkg, pkg_path=self.pkg_path, + pretend=self.pretend, scheduler=self.scheduler), + self._fetcher_exit) + + def _fetcher_exit(self, fetcher): + self._assert_current(fetcher) + if not self.pretend and fetcher.returncode == os.EX_OK: + fetcher.sync_timestamp() + if fetcher.locked: + self._start_task( + AsyncTaskFuture(future=fetcher.async_unlock()), + functools.partial(self._fetcher_exit_unlocked, fetcher)) + else: + self._fetcher_exit_unlocked(fetcher) + + def _fetcher_exit_unlocked(self, fetcher, unlock_task=None): + if unlock_task is not None: + self._assert_current(unlock_task) + unlock_task.future.result() + + self._current_task = None + self.returncode = fetcher.returncode + self._async_wait() + +class _BinpkgFetcherProcess(SpawnProcess): + + __slots__ = ("pkg", "pretend", "locked", "pkg_path", "_lock_obj") + + def _start(self): pkg = self.pkg pretend = self.pretend bintree = pkg.root_config.trees["bintree"] @@ -123,9 +158,7 @@ class BinpkgFetcher(SpawnProcess): _create_pty_or_pipe(copy_term_size=stdout_pipe) return (master_fd, slave_fd) - def _set_returncode(self, wait_retval): - SpawnProcess._set_returncode(self, wait_retval) - if not self.pretend and self.returncode == os.EX_OK: + def sync_timestamp(self): # If possible, update the mtime to match the remote package if # the fetcher didn't already do it automatically. bintree = self.pkg.root_config.trees["bintree"] @@ -151,9 +184,6 @@ class BinpkgFetcher(SpawnProcess): except OSError: pass - if self.locked: - self.unlock() - def lock(self): """ This raises an AlreadyLocked exception if lock() is called @@ -179,10 +209,11 @@ class BinpkgFetcher(SpawnProcess): class AlreadyLocked(portage.exception.PortageException): pass - def unlock(self): + def async_unlock(self): if self._lock_obj is None: - return - self._lock_obj.unlock() + raise AssertionError('already unlocked') + result = self._lock_obj.async_unlock() self._lock_obj = None self.locked = False + return result