From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1Rxtfe-0008Lx-00 for garchives@archives.gentoo.org; Thu, 16 Feb 2012 05:14:19 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 54C8CE0C74; Thu, 16 Feb 2012 05:14:10 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 20D1FE0C74 for ; Thu, 16 Feb 2012 05:14:10 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 8F4061B4002 for ; Thu, 16 Feb 2012 05:14:09 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 56B4BE5400 for ; Thu, 16 Feb 2012 05:14:08 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: <1329369218.9c664779a16f6cbca8a5ffe7f6b0c68572819723.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/_emerge/ X-VCS-Repository: proj/portage X-VCS-Files: pym/_emerge/SubProcess.py X-VCS-Directories: pym/_emerge/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 9c664779a16f6cbca8a5ffe7f6b0c68572819723 X-VCS-Branch: master Date: Thu, 16 Feb 2012 05:14:08 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: 1fdb9c1b-f881-4c16-8289-a6b55558a506 X-Archives-Hash: 17c53230122912b24c1a7bd803928f31 commit: 9c664779a16f6cbca8a5ffe7f6b0c68572819723 Author: Zac Medico gentoo org> AuthorDate: Thu Feb 16 05:13:38 2012 +0000 Commit: Zac Medico gentoo org> CommitDate: Thu Feb 16 05:13:38 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3D9c664779 SubProcess: use non-blocking waitpid This ensures that the EventLoop will not stop due to a waitpid call blocking forever. --- pym/_emerge/SubProcess.py | 39 +++++++++++++++++++++++++++------------ 1 files changed, 27 insertions(+), 12 deletions(-) diff --git a/pym/_emerge/SubProcess.py b/pym/_emerge/SubProcess.py index 926efa7..01004a8 100644 --- a/pym/_emerge/SubProcess.py +++ b/pym/_emerge/SubProcess.py @@ -20,6 +20,9 @@ class SubProcess(AbstractPollTask): # we've sent a kill signal to our subprocess. _cancel_timeout =3D 1000 # 1 second =20 + # Poll interval for process exit status. + _waitpid_interval =3D 1000 # 1 second + def _poll(self): if self.returncode is not None: return self.returncode @@ -77,7 +80,7 @@ class SubProcess(AbstractPollTask): self._orphan_process_warn() else: self._wait_loop() - self._unregister() + if self.returncode is not None: return self.returncode =20 @@ -87,6 +90,25 @@ class SubProcess(AbstractPollTask): "%s: pid is non-integer: %s" % (self.__class__.__name__, repr(self.pid))) =20 + self._waitpid_loop() + + return self.returncode + + def _waitpid_loop(self): + if not self._waitpid_cb(): + return + + timeout_id =3D self.scheduler.timeout_add( + self._waitpid_interval, self._waitpid_cb) + try: + while self.returncode is None: + self.scheduler.iteration() + finally: + self.scheduler.source_remove(timeout_id) + + def _waitpid_cb(self): + if self.returncode is not None: + return False try: # With waitpid and WNOHANG, only check the # first element of the tuple since the second @@ -97,21 +119,13 @@ class SubProcess(AbstractPollTask): raise del e self._set_returncode((self.pid, 1 << 8)) + return False else: if wait_retval[0] !=3D 0: self._set_returncode(wait_retval) - else: - try: - wait_retval =3D os.waitpid(self.pid, 0) - except OSError as e: - if e.errno !=3D errno.ECHILD: - raise - del e - self._set_returncode((self.pid, 1 << 8)) - else: - self._set_returncode(wait_retval) + return False =20 - return self.returncode + return True =20 def _orphan_process_warn(self): pass @@ -141,6 +155,7 @@ class SubProcess(AbstractPollTask): subprocess.Popen.returncode: A negative value -N indicates that the child was terminated by signal N (Unix only). """ + self._unregister() =20 pid, status =3D wait_retval =20