File tree 2 files changed +22
-5
lines changed
2 files changed +22
-5
lines changed Original file line number Diff line number Diff line change 1
1
import collections
2
2
import subprocess
3
3
import warnings
4
+ import os
5
+ import signal
4
6
5
7
from . import protocols
6
8
from . import transports
@@ -144,15 +146,16 @@ def _check_proc(self):
144
146
145
147
def send_signal (self , signal ):
146
148
self ._check_proc ()
147
- self ._proc .send_signal (signal )
149
+ try :
150
+ os .kill (self ._proc .pid , signal )
151
+ except ProcessLookupError :
152
+ pass
148
153
149
154
def terminate (self ):
150
- self ._check_proc ()
151
- self ._proc .terminate ()
155
+ self .send_signal (signal .SIGTERM )
152
156
153
157
def kill (self ):
154
- self ._check_proc ()
155
- self ._proc .kill ()
158
+ self .send_signal (signal .SIGKILL )
156
159
157
160
async def _connect_pipes (self , waiter ):
158
161
try :
Original file line number Diff line number Diff line change @@ -864,6 +864,20 @@ async def main():
864
864
865
865
self .loop .run_until_complete (main ())
866
866
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
+
867
881
868
882
if sys .platform != 'win32' :
869
883
# Unix
You can’t perform that action at this time.
0 commit comments