Skip to content

Commit e8c9f0f

Browse files
use process group
1 parent b6e59d7 commit e8c9f0f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

Lib/test/test_asyncio/test_subprocess.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -184,22 +184,24 @@ def test_kill(self):
184184
self.assertEqual(-signal.SIGKILL, returncode)
185185

186186
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.
187189
blocking_shell_command = f'{sys.executable} -c "import time; time.sleep(100000000)"'
188190
creationflags = 0
189191
if sys.platform == 'win32':
190192
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.
193193
creationflags = CREATE_NEW_PROCESS_GROUP
194194
proc = self.loop.run_until_complete(
195195
asyncio.create_subprocess_shell(blocking_shell_command, stdout=asyncio.subprocess.PIPE,
196-
creationflags=creationflags)
196+
creationflags=creationflags, start_new_session=True)
197197
)
198198
self.loop.run_until_complete(asyncio.sleep(1))
199199
if sys.platform == 'win32':
200200
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)
203205
returncode = self.loop.run_until_complete(proc.wait())
204206
if sys.platform == 'win32':
205207
self.assertIsInstance(returncode, int)

0 commit comments

Comments
 (0)