Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions Lib/asyncio/base_subprocess.py
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
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
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.