From 65ed5bf5dae70ff4993d41a833db62ca8932b382 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Thu, 20 Oct 2022 15:49:19 +0000 Subject: [PATCH 1/2] use process group --- Lib/test/test_asyncio/test_subprocess.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py index fe1d060c77d4c74..84caca3f8885a73 100644 --- a/Lib/test/test_asyncio/test_subprocess.py +++ b/Lib/test/test_asyncio/test_subprocess.py @@ -184,22 +184,24 @@ 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)"' 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) + creationflags=creationflags, start_new_session=True) ) 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() + # On windows it is an alias of terminate which sets the return code + proc.kill() + else: + os.killpg(proc.pid, signal.SIGKILL) returncode = self.loop.run_until_complete(proc.wait()) if sys.platform == 'win32': self.assertIsInstance(returncode, int) From 0c6cadc4c24959f70596c144cdb7ac0a5a5b480f Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Sun, 23 Oct 2022 07:59:29 +0000 Subject: [PATCH 2/2] change command --- Lib/test/test_asyncio/test_subprocess.py | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py index 84caca3f8885a73..20bca3e6b72736d 100644 --- a/Lib/test/test_asyncio/test_subprocess.py +++ b/Lib/test/test_asyncio/test_subprocess.py @@ -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)