]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-31019: Fix multiprocessing.Process.is_alive() (#2875)
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 26 Jul 2017 00:32:42 +0000 (02:32 +0200)
committerGitHub <noreply@github.com>
Wed, 26 Jul 2017 00:32:42 +0000 (02:32 +0200)
multiprocessing.Process.is_alive() now removes the process from the
_children set if the process completed.

The change prevents leaking "dangling" processes.

Lib/multiprocessing/process.py

index ce4ce43cfca6fbd75d144f9cad2e3a31ea0516df..8e500dc93dc6bdbc3c228b9dd851ff98ea83f0d8 100644 (file)
@@ -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):
         '''