[Python-checkins] cpython: Issue #19309: asyncio: make waitpid() wait for all child processes, not only

charles-francois.natali python-checkins at python.org
Sun Oct 20 20:30:31 CEST 2013


http://hg.python.org/cpython/rev/4cdb9f04494b
changeset:   86515:4cdb9f04494b
user:        Charles-François Natali <cf.natali at gmail.com>
date:        Sun Oct 20 20:31:43 2013 +0200
summary:
  Issue #19309: asyncio: make waitpid() wait for all child processes, not only
those in the same process group.

files:
  Lib/asyncio/unix_events.py           |   2 +-
  Lib/test/test_asyncio/test_events.py |  20 ++++++++++++++++
  2 files changed, 21 insertions(+), 1 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
@@ -168,7 +168,7 @@
     def _sig_chld(self):
         try:
             try:
-                pid, status = os.waitpid(0, os.WNOHANG)
+                pid, status = os.waitpid(-1, os.WNOHANG)
             except ChildProcessError:
                 return
             if pid == 0:
diff --git a/Lib/test/test_asyncio/test_events.py b/Lib/test/test_asyncio/test_events.py
--- a/Lib/test/test_asyncio/test_events.py
+++ b/Lib/test/test_asyncio/test_events.py
@@ -1233,6 +1233,26 @@
         self.loop.run_until_complete(proto.completed)
         self.assertEqual(-signal.SIGTERM, proto.returncode)
 
+    @unittest.skipIf(sys.platform == 'win32',
+                     "Don't support subprocess for Windows yet")
+    def test_subprocess_wait_no_same_group(self):
+        proto = None
+        transp = None
+
+        @tasks.coroutine
+        def connect():
+            nonlocal proto
+            # start the new process in a new session
+            transp, proto = yield from self.loop.subprocess_shell(
+                functools.partial(MySubprocessProtocol, self.loop),
+                'exit 7', stdin=None, stdout=None, stderr=None,
+                start_new_session=True)
+            self.assertIsInstance(proto, MySubprocessProtocol)
+
+        self.loop.run_until_complete(connect())
+        self.loop.run_until_complete(proto.completed)
+        self.assertEqual(7, proto.returncode)
+
 
 if sys.platform == 'win32':
     from asyncio import windows_events

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


More information about the Python-checkins mailing list