summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2012-11-11 05:13:20 (GMT)
committerGregory P. Smith <greg@krypto.org>2012-11-11 05:13:20 (GMT)
commitf2705aebb04a1c3f758d7f3383b981e1673525b7 (patch)
tree5925ae4bb0c10a07d71b2a9e43ae2dce2e62eed2
parentc1ce93a4ab0c6e1ed5e7e013789a669871b2257d (diff)
downloadcpython-f2705aebb04a1c3f758d7f3383b981e1673525b7.zip
cpython-f2705aebb04a1c3f758d7f3383b981e1673525b7.tar.gz
cpython-f2705aebb04a1c3f758d7f3383b981e1673525b7.tar.bz2
Fixes issue #14396: Handle the odd rare case of waitpid returning 0
when not expected in subprocess.Popen.wait().
-rw-r--r--Lib/subprocess.py8
-rw-r--r--Misc/NEWS3
2 files changed, 9 insertions, 2 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 0f284d1..8356782 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -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
diff --git a/Misc/NEWS b/Misc/NEWS
index a670e20..c27f829 100644
--- 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.