summaryrefslogtreecommitdiffstats
path: root/Lib/subprocess.py
diff options
context:
space:
mode:
authorGregory P. Smith <greg@krypto.org>2012-11-11 04:52:29 (GMT)
committerGregory P. Smith <greg@krypto.org>2012-11-11 04:52:29 (GMT)
commit2ec82331b25bb1542113f65c70e41932831fe546 (patch)
tree7717cff16dfa4fed8facaf855cf176f47445c29c /Lib/subprocess.py
parent9463e3ac8b230efa2f35e08859cb3db5c6d192b7 (diff)
downloadcpython-2ec82331b25bb1542113f65c70e41932831fe546.zip
cpython-2ec82331b25bb1542113f65c70e41932831fe546.tar.gz
cpython-2ec82331b25bb1542113f65c70e41932831fe546.tar.bz2
Fixes issue #14396: Handle the odd rare case of waitpid returning 0 when
not expected in subprocess.Popen.wait().
Diffstat (limited to 'Lib/subprocess.py')
-rw-r--r--Lib/subprocess.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/subprocess.py b/Lib/subprocess.py
index 83c79ef..35a98c8 100644
--- a/Lib/subprocess.py
+++ b/Lib/subprocess.py
@@ -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