summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2017-07-26 00:32:42 (GMT)
committerGitHub <noreply@github.com>2017-07-26 00:32:42 (GMT)
commit2db64823c20538a6cfc6033661fab5711d2d4585 (patch)
tree31f3943c8c1e052d0469d8f8743238fa3e3332c5
parent627d2c8e8dc9cfe6c1cdfd9b34899eb30b600a88 (diff)
downloadcpython-2db64823c20538a6cfc6033661fab5711d2d4585.zip
cpython-2db64823c20538a6cfc6033661fab5711d2d4585.tar.gz
cpython-2db64823c20538a6cfc6033661fab5711d2d4585.tar.bz2
bpo-31019: Fix multiprocessing.Process.is_alive() (#2875)
multiprocessing.Process.is_alive() now removes the process from the _children set if the process completed. The change prevents leaking "dangling" processes.
-rw-r--r--Lib/multiprocessing/process.py10
1 files changed, 8 insertions, 2 deletions
diff --git a/Lib/multiprocessing/process.py b/Lib/multiprocessing/process.py
index ce4ce43..8e500dc 100644
--- a/Lib/multiprocessing/process.py
+++ b/Lib/multiprocessing/process.py
@@ -148,10 +148,16 @@ class BaseProcess(object):
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:
+ _children.discard(self)
+ return False
def close(self):
'''