summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuido van Rossum <guido@dropbox.com>2013-10-15 09:52:04 -0700
committerGuido van Rossum <guido@dropbox.com>2013-10-15 09:52:04 -0700
commit92fe8ad046f72ce3527127ef7e42ec295adb054c (patch)
treebf7945025c9b2e05d50e236b49590b6b3c207f94
parent784b76010ff0195009c07a514f88a6d2130c9f26 (diff)
parentc165c8161c3b131fed2f315a24d892bbdb8327c0 (diff)
downloadtrollius-92fe8ad046f72ce3527127ef7e42ec295adb054c.tar.gz
Merge _sig_chld() fix into asyncio branch.
-rw-r--r--asyncio/unix_events.py37
-rw-r--r--tests/test_unix_events.py6
2 files changed, 23 insertions, 20 deletions
diff --git a/asyncio/unix_events.py b/asyncio/unix_events.py
index 49761b9..b4bd15d 100644
--- a/asyncio/unix_events.py
+++ b/asyncio/unix_events.py
@@ -163,26 +163,23 @@ class SelectorEventLoop(selector_events.BaseSelectorEventLoop):
def _sig_chld(self):
try:
- while True:
- try:
- pid, status = os.waitpid(0, os.WNOHANG)
- except ChildProcessError:
- break
- if pid == 0:
- continue
- elif os.WIFSIGNALED(status):
- returncode = -os.WTERMSIG(status)
- elif os.WIFEXITED(status):
- returncode = os.WEXITSTATUS(status)
- else:
- # covered by
- # SelectorEventLoopTests.test__sig_chld_unknown_status
- # from tests/unix_events_test.py
- # bug in coverage.py version 3.6 ???
- continue # pragma: no cover
- transp = self._subprocesses.get(pid)
- if transp is not None:
- transp._process_exited(returncode)
+ try:
+ pid, status = os.waitpid(0, 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)
except Exception:
asyncio_log.exception('Unknown exception in SIGCHLD handler')
diff --git a/tests/test_unix_events.py b/tests/test_unix_events.py
index 42dd919..e8a9ec3 100644
--- a/tests/test_unix_events.py
+++ b/tests/test_unix_events.py
@@ -290,6 +290,12 @@ class SelectorEventLoopTests(unittest.TestCase):
m_log.exception.assert_called_with(
'Unknown exception in SIGCHLD handler')
+ @unittest.mock.patch('os.waitpid')
+ def test__sig_chld_process_error(self, m_waitpid):
+ m_waitpid.side_effect = ChildProcessError
+ self.loop._sig_chld()
+ self.assertTrue(m_waitpid.called)
+
class UnixReadPipeTransportTests(unittest.TestCase):