]> granicus.if.org Git - python/commitdiff
Fixes issue #14396: Handle the odd rare case of waitpid returning 0 when
authorGregory P. Smith <greg@krypto.org>
Sun, 11 Nov 2012 04:52:29 +0000 (20:52 -0800)
committerGregory P. Smith <greg@krypto.org>
Sun, 11 Nov 2012 04:52:29 +0000 (20:52 -0800)
not expected in subprocess.Popen.wait().

Lib/subprocess.py
Misc/NEWS

index 83c79ef6245eb5d045fc8e421742a3d6967a8d85..35a98c8969055b66529d4f6448a391a113b73a13 100644 (file)
@@ -1428,7 +1428,7 @@ class Popen(object):
         def wait(self):
             """Wait for child process to terminate.  Returns returncode
             attribute."""
-            if self.returncode is None:
+            while self.returncode is None:
                 try:
                     pid, sts = _eintr_retry_call(os.waitpid, self.pid, 0)
                 except OSError as e:
@@ -1437,8 +1437,12 @@ class Popen(object):
                     # This happens if SIGCLD is set to be ignored or waiting
                     # for child processes has otherwise been disabled for our
                     # process.  This child is dead, we can't get the status.
+                    pid = self.pid
                     sts = 0
-                self._handle_exitstatus(sts)
+                # Check the pid and loop as waitpid has been known to return
+                # 0 even without WNOHANG in odd situations.  issue14396.
+                if pid == self.pid:
+                    self._handle_exitstatus(sts)
             return self.returncode
 
 
index 6a97cbcf8ad635239caa9997d447f6869d35308f..a4f765a68990495e2e0d82ef37b4ebc5f0f5e526 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -10,6 +10,9 @@ What's New in Python 3.2.4
 Core and Builtins
 -----------------
 
+- Issue #14396: Handle the odd rare case of waitpid returning 0 when not
+  expected in subprocess.Popen.wait().
+
 - Issue #9535: Fix pending signals that have been received but not yet
   handled by Python to not persist after os.fork() in the child process.