FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

bpo-43884: Fix asyncio subprocess kill process cleanly when process is blocked by kumaraditya303 · Pull Request #31611 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (2) .rst  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
2 changes: 2 additions & 0 deletions Lib/asyncio/base_subprocess.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ def _process_exited(self, returncode):
if not waiter.cancelled():
waiter.set_result(returncode)
self._exit_waiters = None
self.close()

async def _wait(self):
"""Wait until the process exit and return the process return code.
Expand All @@ -234,6 +235,7 @@ async def _wait(self):
self._exit_waiters.append(waiter)
return await waiter


def _try_finish(self):
assert not self._finished
if self._returncode is None:
Expand Down
14 changes: 14 additions & 0 deletions Lib/test/test_asyncio/test_subprocess.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,20 @@ def test_kill(self):
else:
self.assertEqual(-signal.SIGKILL, returncode)

def test_kill_issue43884(self):
blocking_shell_command = f'{sys.executable} -c "import time; time.sleep(10000)"'
proc = self.loop.run_until_complete(
asyncio.create_subprocess_shell(blocking_shell_command, stdout=asyncio.subprocess.PIPE)
)
self.loop.run_until_complete(asyncio.sleep(1))
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(
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :mod:`asyncio` subprocess to close it's transport when the process exits.

Back | FazBrowse Home | New Git URL