File tree Expand file tree Collapse file tree 2 files changed +22
-5
lines changed
Expand file tree Collapse file tree 2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change 11import collections
22import subprocess
33import warnings
4+ import os
5+ import signal
46
57from . import protocols
68from . import transports
@@ -144,15 +146,16 @@ def _check_proc(self):
144146
145147 def send_signal (self , signal ):
146148 self ._check_proc ()
147- self ._proc .send_signal (signal )
149+ try :
150+ os .kill (self ._proc .pid , signal )
151+ except ProcessLookupError :
152+ pass
148153
149154 def terminate (self ):
150- self ._check_proc ()
151- self ._proc .terminate ()
155+ self .send_signal (signal .SIGTERM )
152156
153157 def kill (self ):
154- self ._check_proc ()
155- self ._proc .kill ()
158+ self .send_signal (signal .SIGKILL )
156159
157160 async def _connect_pipes (self , waiter ):
158161 try :
Original file line number Diff line number Diff line change @@ -864,6 +864,20 @@ async def main():
864864
865865 self .loop .run_until_complete (main ())
866866
867+ def test_subprocess_send_signal_race (self ):
868+ # See https://github.com/python/cpython/issues/87744
869+ async def main ():
870+ for _ in range (10 ):
871+ proc = await asyncio .create_subprocess_exec ('sleep' , '0.1' )
872+ await asyncio .sleep (0.1 )
873+ try :
874+ proc .send_signal (signal .SIGUSR1 )
875+ except ProcessLookupError :
876+ pass
877+ self .assertNotEqual (await proc .wait (), 255 )
878+
879+ self .loop .run_until_complete (main ())
880+
867881
868882if sys .platform != 'win32' :
869883 # Unix
You can’t perform that action at this time.
0 commit comments