From 2ec82331b25bb1542113f65c70e41932831fe546 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sat, 10 Nov 2012 20:52:29 -0800 Subject: [PATCH 1/2] Fixes issue #14396: Handle the odd rare case of waitpid returning 0 when not expected in subprocess.Popen.wait(). --- Lib/subprocess.py | 8 ++++++-- Misc/NEWS | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/Lib/subprocess.py b/Lib/subprocess.py index 83c79ef6245..35a98c89690 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 diff --git a/Misc/NEWS b/Misc/NEWS index 6a97cbcf8ad..a4f765a6899 100644 --- 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. From 6f62b5813431161553cf4f89dbe841268c4b3b8e Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Sat, 10 Nov 2012 21:07:04 -0800 Subject: [PATCH 2/2] move note to the right section --- Misc/NEWS | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Misc/NEWS b/Misc/NEWS index a4f765a6899..a4175e794b4 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -10,9 +10,6 @@ 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. @@ -165,6 +162,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.