[Python-checkins] cpython: Issue #19310: asyncio: fix child processes reaping logic.

charles-francois.natali python-checkins at python.org
Sun Oct 20 23:23:40 CEST 2013


http://hg.python.org/cpython/rev/28397ecf2316
changeset:   86519:28397ecf2316
user:        Charles-François Natali <cf.natali at gmail.com>
date:        Sun Oct 20 23:23:44 2013 +0200
summary:
  Issue #19310: asyncio: fix child processes reaping logic.

files:
  Lib/asyncio/unix_events.py |  36 +++++++++++++------------
  1 files changed, 19 insertions(+), 17 deletions(-)


diff --git a/Lib/asyncio/unix_events.py b/Lib/asyncio/unix_events.py
--- a/Lib/asyncio/unix_events.py
+++ b/Lib/asyncio/unix_events.py
@@ -167,23 +167,25 @@
 
     def _sig_chld(self):
         try:
-            try:
-                pid, status = os.waitpid(-1, os.WNOHANG)
-            except ChildProcessError:
-                return
-            if pid == 0:
-                self.call_soon(self._sig_chld)
-                return
-            elif os.WIFSIGNALED(status):
-                returncode = -os.WTERMSIG(status)
-            elif os.WIFEXITED(status):
-                returncode = os.WEXITSTATUS(status)
-            else:
-                self.call_soon(self._sig_chld)
-                return
-            transp = self._subprocesses.get(pid)
-            if transp is not None:
-                transp._process_exited(returncode)
+            # because of signal coalescing, we must keep calling waitpid() as
+            # long as we're able to reap a child
+            while True:
+                try:
+                    pid, status = os.waitpid(-1, os.WNOHANG)
+                except ChildProcessError:
+                    break
+                if pid == 0:
+                    break
+                elif os.WIFSIGNALED(status):
+                    returncode = -os.WTERMSIG(status)
+                elif os.WIFEXITED(status):
+                    returncode = os.WEXITSTATUS(status)
+                else:
+                    # shouldn't happen
+                    continue
+                transp = self._subprocesses.get(pid)
+                if transp is not None:
+                    transp._process_exited(returncode)
         except Exception:
             logger.exception('Unknown exception in SIGCHLD handler')
 

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list