mirror of
https://github.com/python/cpython.git
synced 2025-10-31 21:51:50 +00:00
gh-88050: Fix asyncio subprocess to kill process cleanly when process is blocked (#32073)
This commit is contained in:
parent
0e72606dd4
commit
7015e13797
3 changed files with 33 additions and 6 deletions
|
|
@ -215,14 +215,10 @@ def _process_exited(self, returncode):
|
|||
# object. On Python 3.6, it is required to avoid a ResourceWarning.
|
||||
self._proc.returncode = returncode
|
||||
self._call(self._protocol.process_exited)
|
||||
for p in self._pipes.values():
|
||||
p.pipe.close()
|
||||
self._try_finish()
|
||||
|
||||
# wake up futures waiting for wait()
|
||||
for waiter in self._exit_waiters:
|
||||
if not waiter.cancelled():
|
||||
waiter.set_result(returncode)
|
||||
self._exit_waiters = None
|
||||
|
||||
async def _wait(self):
|
||||
"""Wait until the process exit and return the process return code.
|
||||
|
||||
|
|
@ -247,6 +243,11 @@ def _call_connection_lost(self, exc):
|
|||
try:
|
||||
self._protocol.connection_lost(exc)
|
||||
finally:
|
||||
# wake up futures waiting for wait()
|
||||
for waiter in self._exit_waiters:
|
||||
if not waiter.cancelled():
|
||||
waiter.set_result(self._returncode)
|
||||
self._exit_waiters = None
|
||||
self._loop = None
|
||||
self._proc = None
|
||||
self._protocol = None
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue