@@ -44,6 +44,16 @@ def _sighandler_noop(signum, frame):
44
44
pass
45
45
46
46
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
+
47
57
class _UnixSelectorEventLoop (selector_events .BaseSelectorEventLoop ):
48
58
"""Unix event loop.
49
59
@@ -941,7 +951,7 @@ def _do_wait(self, pid):
941
951
" will report returncode 255" ,
942
952
pid )
943
953
else :
944
- returncode = _compute_returncode (status )
954
+ returncode = waitstatus_to_exitcode (status )
945
955
946
956
os .close (pidfd )
947
957
callback (pid , returncode , * args )
@@ -956,20 +966,6 @@ def remove_child_handler(self, pid):
956
966
return True
957
967
958
968
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
-
973
969
class BaseChildWatcher (AbstractChildWatcher ):
974
970
975
971
def __init__ (self ):
@@ -1080,7 +1076,7 @@ def _do_waitpid(self, expected_pid):
1080
1076
# The child process is still alive.
1081
1077
return
1082
1078
1083
- returncode = _compute_returncode (status )
1079
+ returncode = waitstatus_to_exitcode (status )
1084
1080
if self ._loop .get_debug ():
1085
1081
logger .debug ('process %s exited with returncode %s' ,
1086
1082
expected_pid , returncode )
@@ -1173,7 +1169,7 @@ def _do_waitpid_all(self):
1173
1169
# A child process is still alive.
1174
1170
return
1175
1171
1176
- returncode = _compute_returncode (status )
1172
+ returncode = waitstatus_to_exitcode (status )
1177
1173
1178
1174
with self ._lock :
1179
1175
try :
@@ -1296,7 +1292,7 @@ def _do_waitpid(self, expected_pid):
1296
1292
# The child process is still alive.
1297
1293
return
1298
1294
1299
- returncode = _compute_returncode (status )
1295
+ returncode = waitstatus_to_exitcode (status )
1300
1296
debug_log = True
1301
1297
try :
1302
1298
loop , callback , args = self ._callbacks .pop (pid )
@@ -1399,7 +1395,7 @@ def _do_waitpid(self, loop, expected_pid, callback, args):
1399
1395
"Unknown child process pid %d, will report returncode 255" ,
1400
1396
pid )
1401
1397
else :
1402
- returncode = _compute_returncode (status )
1398
+ returncode = waitstatus_to_exitcode (status )
1403
1399
if loop .get_debug ():
1404
1400
logger .debug ('process %s exited with returncode %s' ,
1405
1401
expected_pid , returncode )
0 commit comments