Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
change command
  • Loading branch information
kumaraditya303 authored Oct 23, 2022
commit 0c6cadc4c24959f70596c144cdb7ac0a5a5b480f
17 changes: 9 additions & 8 deletions Lib/test/test_asyncio/test_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -184,24 +184,25 @@ def test_kill(self):
self.assertEqual(-signal.SIGKILL, returncode)

def test_kill_issue43884(self):
# This test create a new process group so that killing process
# kills the process and all its children.
blocking_shell_command = f'{sys.executable} -c "import time; time.sleep(100000000)"'
if sys.platform == 'win32':
blocking_shell_command = f'{sys.executable} -c "import time; time.sleep(100000000)"'
else:
blocking_shell_command = 'sleep 1; sleep 1'
creationflags = 0
if sys.platform == 'win32':
from subprocess import CREATE_NEW_PROCESS_GROUP
# On windows create a new process group so that killing process
# kills the process and all its children.
creationflags = CREATE_NEW_PROCESS_GROUP
proc = self.loop.run_until_complete(
asyncio.create_subprocess_shell(blocking_shell_command, stdout=asyncio.subprocess.PIPE,
creationflags=creationflags, start_new_session=True)
creationflags=creationflags)
)
self.loop.run_until_complete(asyncio.sleep(1))
if sys.platform == 'win32':
proc.send_signal(signal.CTRL_BREAK_EVENT)
# On windows it is an alias of terminate which sets the return code
proc.kill()
else:
os.killpg(proc.pid, signal.SIGKILL)
# On windows it is an alias of terminate which sets the return code
proc.kill()
returncode = self.loop.run_until_complete(proc.wait())
if sys.platform == 'win32':
self.assertIsInstance(returncode, int)
Expand Down