bpo-40364: asyncio uses os.waitstatus_to_exitcode() (GH-23798) · python/cpython@99d28c5
@@ -44,6 +44,16 @@ def _sighandler_noop(signum, frame):
4444pass
4545464647+def waitstatus_to_exitcode(status):
48+try:
49+return os.waitstatus_to_exitcode(status)
50+except ValueError:
51+# The child exited, but we don't understand its status.
52+# This shouldn't happen, but if it does, let's just
53+# return that status; perhaps that helps debug it.
54+return status
55+56+4757class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
4858"""Unix event loop.
4959@@ -941,7 +951,7 @@ def _do_wait(self, pid):
941951" will report returncode 255",
942952pid)
943953else:
944-returncode = _compute_returncode(status)
954+returncode = waitstatus_to_exitcode(status)
945955946956os.close(pidfd)
947957callback(pid, returncode, *args)
@@ -956,20 +966,6 @@ def remove_child_handler(self, pid):
956966return True
957967958968959-def _compute_returncode(status):
960-if os.WIFSIGNALED(status):
961-# The child process died because of a signal.
962-return -os.WTERMSIG(status)
963-elif os.WIFEXITED(status):
964-# The child process exited (e.g sys.exit()).
965-return os.WEXITSTATUS(status)
966-else:
967-# The child exited, but we don't understand its status.
968-# This shouldn't happen, but if it does, let's just
969-# return that status; perhaps that helps debug it.
970-return status
971-972-973969class BaseChildWatcher(AbstractChildWatcher):
974970975971def __init__(self):
@@ -1080,7 +1076,7 @@ def _do_waitpid(self, expected_pid):
10801076# The child process is still alive.
10811077return
108210781083-returncode = _compute_returncode(status)
1079+returncode = waitstatus_to_exitcode(status)
10841080if self._loop.get_debug():
10851081logger.debug('process %s exited with returncode %s',
10861082expected_pid, returncode)
@@ -1173,7 +1169,7 @@ def _do_waitpid_all(self):
11731169# A child process is still alive.
11741170return
117511711176-returncode = _compute_returncode(status)
1172+returncode = waitstatus_to_exitcode(status)
1177117311781174with self._lock:
11791175try:
@@ -1296,7 +1292,7 @@ def _do_waitpid(self, expected_pid):
12961292# The child process is still alive.
12971293return
129812941299-returncode = _compute_returncode(status)
1295+returncode = waitstatus_to_exitcode(status)
13001296debug_log = True
13011297try:
13021298loop, callback, args = self._callbacks.pop(pid)
@@ -1399,7 +1395,7 @@ def _do_waitpid(self, loop, expected_pid, callback, args):
13991395"Unknown child process pid %d, will report returncode 255",
14001396pid)
14011397else:
1402-returncode = _compute_returncode(status)
1398+returncode = waitstatus_to_exitcode(status)
14031399if loop.get_debug():
14041400logger.debug('process %s exited with returncode %s',
14051401expected_pid, returncode)