summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_asyncio
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-10-05 17:48:48 (GMT)
committerGitHub <noreply@github.com>2022-10-05 17:48:48 (GMT)
commitaec133347e9307591d53ad825c0ed82a500e094d (patch)
tree8e4f38b521a0efe6ee4070ad6e6a3d84abb3d464 /Lib/test/test_asyncio
parent5c8aa2e0f224179e5ee3086b295a735610e9e5c7 (diff)
downloadcpython-aec133347e9307591d53ad825c0ed82a500e094d.zip
cpython-aec133347e9307591d53ad825c0ed82a500e094d.tar.gz
cpython-aec133347e9307591d53ad825c0ed82a500e094d.tar.bz2
gh-88050: Fix asyncio subprocess to kill process cleanly when process is blocked (GH-32073)
(cherry picked from commit 7015e1379791cbf19908cd1a7c668a5d6e7165d5) Co-authored-by: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_asyncio')
-rw-r--r--Lib/test/test_asyncio/test_subprocess.py25
1 files changed, 25 insertions, 0 deletions
diff --git a/Lib/test/test_asyncio/test_subprocess.py b/Lib/test/test_asyncio/test_subprocess.py
index 961c463..9bc60b9 100644
--- a/Lib/test/test_asyncio/test_subprocess.py
+++ b/Lib/test/test_asyncio/test_subprocess.py
@@ -1,4 +1,5 @@
import os
+import shutil
import signal
import sys
import unittest
@@ -182,6 +183,30 @@ class SubprocessMixin:
else:
self.assertEqual(-signal.SIGKILL, returncode)
+ def test_kill_issue43884(self):
+ 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)
+ )
+ 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()
+ returncode = self.loop.run_until_complete(proc.wait())
+ if sys.platform == 'win32':
+ self.assertIsInstance(returncode, int)
+ # expect 1 but sometimes get 0
+ else:
+ self.assertEqual(-signal.SIGKILL, returncode)
+
def test_terminate(self):
args = PROGRAM_BLOCKED
proc = self.loop.run_until_complete(