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

Lib/subprocess.py
Misc/NEWS

index 0f284d1f0d9b5595c2e7fd87bf1309bc1b95c8b0..83567822242105c8056521b489c087c12e9daa1b 100644 (file)
@@ -1303,7 +1303,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:
@@ -1312,8 +1312,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 a670e2026c44bc445c8b78e13dcb9f4df568211f..c27f82955b8dfb54f4f2e44699446c664c27a633 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -143,6 +143,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #14396: Handle the odd rare case of waitpid returning 0 when not
+  expected in subprocess.Popen.wait().
+
 - Issue #16411: Fix a bug where zlib.decompressobj().flush() might try to access
   previously-freed memory. Patch by Serhiy Storchaka.