Skip to content

Commit 2db6482

Browse files
authored
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.
1 parent 627d2c8 commit 2db6482

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

Lib/multiprocessing/process.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,16 @@ def is_alive(self):
148148
if self is _current_process:
149149
return True
150150
assert self._parent_pid == os.getpid(), 'can only test a child process'
151+
151152
if self._popen is None:
152153
return False
153-
self._popen.poll()
154-
return self._popen.returncode is None
154+
155+
returncode = self._popen.poll()
156+
if returncode is None:
157+
return True
158+
else:
159+
_children.discard(self)
160+
return False
155161

156162
def close(self):
157163
'''

0 commit comments

Comments
 (0)