|
3 | 3 | import collections
|
4 | 4 | import errno
|
5 | 5 | import fcntl
|
6 |
| -import functools |
7 | 6 | import os
|
8 | 7 | import signal
|
9 | 8 | import socket
|
@@ -167,22 +166,26 @@ def _reg_sigchld(self):
|
167 | 166 |
|
168 | 167 | def _sig_chld(self):
|
169 | 168 | try:
|
170 |
| - # because of signal coalescing, we must keep calling waitpid() as |
171 |
| - # long as we're able to reap a child |
| 169 | + # Because of signal coalescing, we must keep calling waitpid() as |
| 170 | + # long as we're able to reap a child. |
172 | 171 | while True:
|
173 | 172 | try:
|
174 | 173 | pid, status = os.waitpid(-1, os.WNOHANG)
|
175 | 174 | except ChildProcessError:
|
176 |
| - break |
| 175 | + break # No more child processes exist. |
177 | 176 | if pid == 0:
|
178 |
| - break |
| 177 | + break # All remaining child processes are still alive. |
179 | 178 | elif os.WIFSIGNALED(status):
|
| 179 | + # A child process died because of a signal. |
180 | 180 | returncode = -os.WTERMSIG(status)
|
181 | 181 | elif os.WIFEXITED(status):
|
| 182 | + # A child process exited (e.g. sys.exit()). |
182 | 183 | returncode = os.WEXITSTATUS(status)
|
183 | 184 | else:
|
184 |
| - # shouldn't happen |
185 |
| - continue |
| 185 | + # A child exited, but we don't understand its status. |
| 186 | + # This shouldn't happen, but if it does, let's just |
| 187 | + # return that status; perhaps that helps debug it. |
| 188 | + returncode = status |
186 | 189 | transp = self._subprocesses.get(pid)
|
187 | 190 | if transp is not None:
|
188 | 191 | transp._process_exited(returncode)
|
@@ -480,18 +483,15 @@ def _post_init(self):
|
480 | 483 | loop = self._loop
|
481 | 484 | if proc.stdin is not None:
|
482 | 485 | transp, proto = yield from loop.connect_write_pipe(
|
483 |
| - functools.partial( |
484 |
| - _UnixWriteSubprocessPipeProto, self, STDIN), |
| 486 | + lambda: _UnixWriteSubprocessPipeProto(self, STDIN), |
485 | 487 | proc.stdin)
|
486 | 488 | if proc.stdout is not None:
|
487 | 489 | transp, proto = yield from loop.connect_read_pipe(
|
488 |
| - functools.partial( |
489 |
| - _UnixReadSubprocessPipeProto, self, STDOUT), |
| 490 | + lambda: _UnixReadSubprocessPipeProto(self, STDOUT), |
490 | 491 | proc.stdout)
|
491 | 492 | if proc.stderr is not None:
|
492 | 493 | transp, proto = yield from loop.connect_read_pipe(
|
493 |
| - functools.partial( |
494 |
| - _UnixReadSubprocessPipeProto, self, STDERR), |
| 494 | + lambda: _UnixReadSubprocessPipeProto(self, STDERR), |
495 | 495 | proc.stderr)
|
496 | 496 | if not self._pipes:
|
497 | 497 | self._try_connected()
|
|
0 commit comments