Skip to content

Commit

Permalink
pythongh-105288: wake up exit waiters after sub-process exits
Browse files Browse the repository at this point in the history
  • Loading branch information
keuin committed Jun 4, 2023
1 parent 1237fb6 commit 54bbc06
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
14 changes: 9 additions & 5 deletions Lib/asyncio/base_subprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,14 @@ def _process_exited(self, returncode):
self._call(self._protocol.process_exited)

self._try_finish()
self._wakeup_exit_waiters()

def _wakeup_exit_waiters(self):
# wake up futures waiting for wait()
for waiter in self._exit_waiters:
if not waiter.cancelled():
waiter.set_result(self._returncode)
self._exit_waiters = []

async def _wait(self):
"""Wait until the process exit and return the process return code.
Expand All @@ -242,11 +250,7 @@ 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._wakeup_exit_waiters()
self._loop = None
self._proc = None
self._protocol = None
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Exit waiters are not resolved after subprocess handled by :class:`asyncio.Task`
exits. This will causes a recent :func:`asyncio.wait` call hang forever if there
are objects that are not :type:`Awaitable` yield from its first parameter.

0 comments on commit 54bbc06

Please sign in to comment.