Skip to content

Commit b65cb8a

Browse files
authored
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 2db6482)
1 parent ec9a712 commit b65cb8a

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
@@ -156,10 +156,16 @@ def is_alive(self):
156156
if self is _current_process:
157157
return True
158158
assert self._parent_pid == os.getpid(), 'can only test a child process'
159+
159160
if self._popen is None:
160161
return False
161-
self._popen.poll()
162-
return self._popen.returncode is None
162+
163+
returncode = self._popen.poll()
164+
if returncode is None:
165+
return True
166+
else:
167+
_current_process._children.discard(self)
168+
return False
163169

164170
@property
165171
def name(self):

0 commit comments

Comments
 (0)