(original) (raw)

changeset: 80367:82711f5ab507 branch: 2.7 parent: 80361:9b711422c98f user: Gregory P. Smith greg@krypto.org date: Sat Nov 10 21:13:20 2012 -0800 files: Lib/subprocess.py Misc/NEWS description: Fixes issue #14396: Handle the odd rare case of waitpid returning 0 when not expected in subprocess.Popen.wait(). diff -r 9b711422c98f -r 82711f5ab507 Lib/subprocess.py --- a/Lib/subprocess.py Sat Nov 10 20:38:17 2012 -0800 +++ b/Lib/subprocess.py Sat Nov 10 21:13:20 2012 -0800 @@ -1303,7 +1303,7 @@ 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 @@ # 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 -r 9b711422c98f -r 82711f5ab507 Misc/NEWS --- a/Misc/NEWS Sat Nov 10 20:38:17 2012 -0800 +++ b/Misc/NEWS Sat Nov 10 21:13:20 2012 -0800 @@ -143,6 +143,9 @@ 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. /greg@krypto.org