With waitpid and WNOHANG, only check the first element of the tuple v2.2_rc85
authorZac Medico <zmedico@gentoo.org>
Mon, 20 Sep 2010 02:58:29 +0000 (19:58 -0700)
committerZac Medico <zmedico@gentoo.org>
Mon, 20 Sep 2010 02:58:29 +0000 (19:58 -0700)
since the second element may vary (bug #337465, comment #12).

pym/_emerge/SubProcess.py
pym/_emerge/actions.py
pym/portage/process.py

index 0013d73911957e7945616fee676d08e6db80769d..b2b19d54dc4b86f030352f354b9bfe0c881c1da2 100644 (file)
@@ -25,6 +25,9 @@ class SubProcess(AbstractPollTask):
                        return self.returncode
 
                try:
+                       # With waitpid and WNOHANG, only check the
+                       # first element of the tuple since the second
+                       # element may vary (bug #337465).
                        retval = os.waitpid(self.pid, os.WNOHANG)
                except OSError as e:
                        if e.errno != errno.ECHILD:
@@ -32,7 +35,7 @@ class SubProcess(AbstractPollTask):
                        del e
                        retval = (self.pid, 1)
 
-               if retval == (0, 0):
+               if retval[0] == 0:
                        return None
                self._set_returncode(retval)
                return self.returncode
@@ -81,6 +84,9 @@ class SubProcess(AbstractPollTask):
                                return self.returncode
 
                try:
+                       # With waitpid and WNOHANG, only check the
+                       # first element of the tuple since the second
+                       # element may vary (bug #337465).
                        wait_retval = os.waitpid(self.pid, os.WNOHANG)
                except OSError as e:
                        if e.errno != errno.ECHILD:
@@ -88,7 +94,7 @@ class SubProcess(AbstractPollTask):
                        del e
                        self._set_returncode((self.pid, 1))
                else:
-                       if wait_retval != (0, 0):
+                       if wait_retval[0] != 0:
                                self._set_returncode(wait_retval)
                        else:
                                try:
index eb02a0304fed61570d44e87e80f917c48470e80b..92eb18b740146628ff6fc8ff7b73204251726b38 100644 (file)
@@ -2177,7 +2177,10 @@ def action_sync(settings, trees, mtimedb, myopts, myaction):
                                except portage.exception.AlarmSignal:
                                        # timed out
                                        print('timed out')
-                                       if mypids and os.waitpid(mypids[0], os.WNOHANG) == (0,0):
+                                       # With waitpid and WNOHANG, only check the
+                                       # first element of the tuple since the second
+                                       # element may vary (bug #337465).
+                                       if mypids and os.waitpid(mypids[0], os.WNOHANG)[0] == 0:
                                                os.kill(mypids[0], signal.SIGTERM)
                                                os.waitpid(mypids[0], 0)
                                        # This is the same code rsync uses for timeout.
index 2787e08844ed33a73299384cea727374d52946a2..37b482a0ef3571c02084df478a5b1f223c9fe970 100644 (file)
@@ -135,7 +135,10 @@ def cleanup():
        while spawned_pids:
                pid = spawned_pids.pop()
                try:
-                       if os.waitpid(pid, os.WNOHANG) == (0, 0):
+                       # With waitpid and WNOHANG, only check the
+                       # first element of the tuple since the second
+                       # element may vary (bug #337465).
+                       if os.waitpid(pid, os.WNOHANG)[0] == 0:
                                os.kill(pid, signal.SIGTERM)
                                os.waitpid(pid, 0)
                except OSError:
@@ -289,7 +292,10 @@ def spawn(mycommand, env={}, opt_name=None, fd_pipes=None, returnpid=False,
                        # If it failed, kill off anything else that
                        # isn't dead yet.
                        for pid in mypids:
-                               if os.waitpid(pid, os.WNOHANG) == (0,0):
+                               # With waitpid and WNOHANG, only check the
+                               # first element of the tuple since the second
+                               # element may vary (bug #337465).
+                               if os.waitpid(pid, os.WNOHANG)[0] == 0:
                                        os.kill(pid, signal.SIGTERM)
                                        os.waitpid(pid, 0)
                                spawned_pids.remove(pid)