]> granicus.if.org Git - python/commitdiff
bpo-31019: Fix multiprocessing.Process.is_alive() (#2875) (#2882)
authorVictor Stinner <victor.stinner@gmail.com>
Wed, 26 Jul 2017 15:54:42 +0000 (17:54 +0200)
committerGitHub <noreply@github.com>
Wed, 26 Jul 2017 15:54:42 +0000 (17:54 +0200)
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)

Lib/multiprocessing/process.py

index 16c4e1eb3437367b4e387925ff6c62b5f0001660..11c8fca360fa22edc255dbf16bf1b38f948b3e47 100644 (file)
@@ -156,10 +156,16 @@ class Process(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:
+            _current_process._children.discard(self)
+            return False
 
     @property
     def name(self):