[Python-checkins] bpo-31019: Fix multiprocessing.Process.is_alive() (#2875) (#2882)
Victor Stinner
webhook-mailer at python.org
Wed Jul 26 11:54:48 EDT 2017
https://github.com/python/cpython/commit/b65cb8a35641675d44af84c9b18c40c6094f03ef
commit: b65cb8a35641675d44af84c9b18c40c6094f03ef
branch: 2.7
author: Victor Stinner <victor.stinner at gmail.com>
committer: GitHub <noreply at github.com>
date: 2017-07-26T17:54:42+02:00
summary:
bpo-31019: Fix multiprocessing.Process.is_alive() (#2875) (#2882)
multiprocessing.Process.is_alive() now removes the process from the
_children set if the process completed.
The change prevents leaking "dangling" processes.
(cherry picked from commit 2db64823c20538a6cfc6033661fab5711d2d4585)
files:
M Lib/multiprocessing/process.py
diff --git a/Lib/multiprocessing/process.py b/Lib/multiprocessing/process.py
index 16c4e1eb343..11c8fca360f 100644
--- a/Lib/multiprocessing/process.py
+++ b/Lib/multiprocessing/process.py
@@ -156,10 +156,16 @@ def is_alive(self):
if self is _current_process:
return True
assert self._parent_pid == os.getpid(), 'can only test a child process'
+
if self._popen is None:
return False
- self._popen.poll()
- return self._popen.returncode is None
+
+ returncode = self._popen.poll()
+ if returncode is None:
+ return True
+ else:
+ _current_process._children.discard(self)
+ return False
@property
def name(self):
More information about the Python-checkins
mailing list