22import resource
33from asyncio import ThreadedChildWatcher
44from asyncio .log import logger
5- from asyncio .unix_events import _compute_returncode
65
76# based on https://www.enricozini.org/blog/2019/debian/getting-rusage-of-child-processes-on-python-s-asyncio/
87from typing import Dict
98
109
10+ # copied from unix_events.ThreadedChildWatcher on Python 3.10.6
11+ def waitstatus_to_exitcode (status ):
12+ try :
13+ return os .waitstatus_to_exitcode (status )
14+ except ValueError :
15+ # The child exited, but we don't understand its status.
16+ # This shouldn't happen, but if it does, let's just
17+ # return that status; perhaps that helps debug it.
18+ return status
19+
20+
1121class RusageThreadedChildWatcher (ThreadedChildWatcher ):
1222 rusages : Dict [int , resource .struct_rusage ] = {}
1323
14- # copied from unix_events.ThreadedChildWatcher on Python 3.9.7
24+ # copied from unix_events.ThreadedChildWatcher on Python 3.10.6
1525 def _do_waitpid (self , loop , expected_pid , callback , args ):
1626 assert expected_pid > 0
1727
@@ -27,7 +37,7 @@ def _do_waitpid(self, loop, expected_pid, callback, args):
2737 "Unknown child process pid %d, will report returncode 255" ,
2838 pid )
2939 else :
30- returncode = _compute_returncode (status )
40+ returncode = waitstatus_to_exitcode (status )
3141 if loop .get_debug ():
3242 logger .debug ('process %s exited with returncode %s' ,
3343 expected_pid , returncode )
0 commit comments