gh-88050: Fix asyncio subprocess to kill process cleanly when process is blocked (#32073)

This commit is contained in:
Kumar Aditya 2022-10-05 22:45:31 +05:30 committed by GitHub
parent 0e72606dd4
commit 7015e13797
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 6 deletions

View file

@ -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