Skip to content

Commit 99d28c5

Browse files
authored
bpo-40364: asyncio uses os.waitstatus_to_exitcode() (GH-23798)
test_unix_events.py no longer checks if waitstatus_to_exitcode() mock has been called or not to make the test more functional, rather than checking the exact implementation.
1 parent 5f0fe8e commit 99d28c5

File tree

2 files changed

+80
-215
lines changed

2 files changed

+80
-215
lines changed

Lib/asyncio/unix_events.py

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,16 @@ def _sighandler_noop(signum, frame):
4444
pass
4545

4646

47+
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+
4757
class _UnixSelectorEventLoop(selector_events.BaseSelectorEventLoop):
4858
"""Unix event loop.
4959
@@ -941,7 +951,7 @@ def _do_wait(self, pid):
941951
" will report returncode 255",
942952
pid)
943953
else:
944-
returncode = _compute_returncode(status)
954+
returncode = waitstatus_to_exitcode(status)
945955

946956
os.close(pidfd)
947957
callback(pid, returncode, *args)
@@ -956,20 +966,6 @@ def remove_child_handler(self, pid):
956966
return True
957967

958968

959-
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-
973969
class BaseChildWatcher(AbstractChildWatcher):
974970

975971
def __init__(self):
@@ -1080,7 +1076,7 @@ def _do_waitpid(self, expected_pid):
10801076
# The child process is still alive.
10811077
return
10821078

1083-
returncode = _compute_returncode(status)
1079+
returncode = waitstatus_to_exitcode(status)
10841080
if self._loop.get_debug():
10851081
logger.debug('process %s exited with returncode %s',
10861082
expected_pid, returncode)
@@ -1173,7 +1169,7 @@ def _do_waitpid_all(self):
11731169
# A child process is still alive.
11741170
return
11751171

1176-
returncode = _compute_returncode(status)
1172+
returncode = waitstatus_to_exitcode(status)
11771173

11781174
with self._lock:
11791175
try:
@@ -1296,7 +1292,7 @@ def _do_waitpid(self, expected_pid):
12961292
# The child process is still alive.
12971293
return
12981294

1299-
returncode = _compute_returncode(status)
1295+
returncode = waitstatus_to_exitcode(status)
13001296
debug_log = True
13011297
try:
13021298
loop, 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",
14001396
pid)
14011397
else:
1402-
returncode = _compute_returncode(status)
1398+
returncode = waitstatus_to_exitcode(status)
14031399
if loop.get_debug():
14041400
logger.debug('process %s exited with returncode %s',
14051401
expected_pid, returncode)

0 commit comments

Comments
 (0)