@@ -184,22 +184,24 @@ def test_kill(self):
184
184
self .assertEqual (- signal .SIGKILL , returncode )
185
185
186
186
def test_kill_issue43884 (self ):
187
+ # This test create a new process group so that killing process
188
+ # kills the process and all its children.
187
189
blocking_shell_command = f'{ sys .executable } -c "import time; time.sleep(100000000)"'
188
190
creationflags = 0
189
191
if sys .platform == 'win32' :
190
192
from subprocess import CREATE_NEW_PROCESS_GROUP
191
- # On windows create a new process group so that killing process
192
- # kills the process and all its children.
193
193
creationflags = CREATE_NEW_PROCESS_GROUP
194
194
proc = self .loop .run_until_complete (
195
195
asyncio .create_subprocess_shell (blocking_shell_command , stdout = asyncio .subprocess .PIPE ,
196
- creationflags = creationflags )
196
+ creationflags = creationflags , start_new_session = True )
197
197
)
198
198
self .loop .run_until_complete (asyncio .sleep (1 ))
199
199
if sys .platform == 'win32' :
200
200
proc .send_signal (signal .CTRL_BREAK_EVENT )
201
- # On windows it is an alias of terminate which sets the return code
202
- proc .kill ()
201
+ # On windows it is an alias of terminate which sets the return code
202
+ proc .kill ()
203
+ else :
204
+ os .killpg (proc .pid , signal .SIGKILL )
203
205
returncode = self .loop .run_until_complete (proc .wait ())
204
206
if sys .platform == 'win32' :
205
207
self .assertIsInstance (returncode , int )
0 commit comments