Skip to content

gh-119710: Let asyncio Process.wait() finish on only process exit. - #151983

Merged
kumaraditya303 merged 6 commits into
python:mainfrom
tapetersen:gh-119710-subprocess-wait-hang
Jul 19, 2026
Merged

gh-119710: Let asyncio Process.wait() finish on only process exit.#151983
kumaraditya303 merged 6 commits into
python:mainfrom
tapetersen:gh-119710-subprocess-wait-hang

Conversation

@tapetersen

Copy link
Copy Markdown
Contributor

gh-119710: Let asyncio Process.wait() finish on only process exit

Letting Process.wait() only wait on actual process return is closer to how it's documented and consistent with Popen.wait(). This also reduces complexity for waking waiters which was inconsistend depending on ordering of wait/exit.

@python-cla-bot

python-cla-botBot commented Jun 23, 2026

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@tapetersen
tapetersenforce-pushed the gh-119710-subprocess-wait-hang branch 3 times, most recently from e774576 to f6df3f5CompareJune 23, 2026 12:07
Comment threadLib/test/test_asyncio/test_subprocess.py
Comment threadLib/asyncio/base_subprocess.py Outdated
@tapetersen
tapetersen marked this pull request as ready for review June 23, 2026 12:21
Comment threadLib/test/test_asyncio/test_subprocess.py Outdated
Letting Process.wait() only wait on actual process return is closer to
how it's documented and consistent with Popen.wait(). This also reduces
complexity for waking waiters which was inconsistend depending on
ordering of wait/exit.
@tapetersen
tapetersenforce-pushed the gh-119710-subprocess-wait-hang branch from f6df3f5 to e703a76CompareJuly 17, 2026 13:57
Comment threadLib/test/test_asyncio/test_subprocess.py Outdated
Comment threadLib/test/test_asyncio/test_subprocess.py Outdated
@kumaraditya303kumaraditya303 added topic-asyncio needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jul 17, 2026
Comment threadLib/test/test_asyncio/test_subprocess.py Outdated
@kumaraditya303kumaraditya303 added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Jul 19, 2026
@kumaraditya303

kumaraditya303 commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

I simplified the added test and also fixed it, now it correctly fails on main branch but passes on this. here's the failure on windows:

======================================================================ERROR: test_wait_even_if_pipe_is_open (test.test_asyncio.test_subprocess.SubprocessProactorTests.test_wait_even_if_pipe_is_open)----------------------------------------------------------------------Traceback (most recent call last): File "D:\cpython\Lib\asyncio\tasks.py", line 488, in wait_for return await fut ^^^^^^^^^ File "D:\cpython\Lib\asyncio\subprocess.py", line 137, in wait return await self._transport._wait() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\cpython\Lib\asyncio\base_subprocess.py", line 255, in _wait return await waiter ^^^^^^^^^^^^asyncio.exceptions.CancelledErrorThe above exception was the direct cause of the following exception:Traceback (most recent call last): File "D:\cpython\Lib\test\test_asyncio\test_subprocess.py", line 446, in test_wait_even_if_pipe_is_open self.loop.run_until_complete(run()) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^ File "D:\cpython\Lib\asyncio\base_events.py", line 725, in run_until_complete return future.result() ~~~~~~~~~~~~~^^ File "D:\cpython\Lib\test\test_asyncio\test_subprocess.py", line 436, in run returncode = await asyncio.wait_for( ^^^^^^^^^^^^^^^^^^^^^^^ wait_proc, timeout=support.SHORT_TIMEOUT) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\cpython\Lib\asyncio\tasks.py", line 487, in wait_for async with timeouts.timeout(timeout): ~~~~~~~~~~~~~~~~^^^^^^^^^ File "D:\cpython\Lib\asyncio\timeouts.py", line 115, in __aexit__ raise TimeoutError from exc_valTimeoutError----------------------------------------------------------------------Ran 41 tests in 35.871s

@kumaraditya303
kumaraditya303 merged commit f252132 into python:mainJul 19, 2026
59 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @tapetersen for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

Copy link
Copy Markdown

GH-154170 is a backport of this pull request to the 3.15 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jul 19, 2026
@bedevere-app

Copy link
Copy Markdown

GH-154171 is a backport of this pull request to the 3.14 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.14 bugs and security fixes label Jul 19, 2026
@bedevere-app

Copy link
Copy Markdown

GH-154172 is a backport of this pull request to the 3.13 branch.

@bedevere-appbedevere-appBot removed the needs backport to 3.13 bugs and security fixes label Jul 19, 2026
@tapetersen

Copy link
Copy Markdown
ContributorAuthor

@kumaraditya303 Thanks for the review and windows fix.

kumaraditya303 added a commit to miss-islington/cpython that referenced this pull request Jul 20, 2026
… and not wait for closing of pipes (pythonGH-151983)
(cherry picked from commit f252132)
Co-authored-by: Tobias Alex-Petersen <tobias.alex.petersen@gmail.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
kumaraditya303 added a commit that referenced this pull request Jul 20, 2026
…t and not wait for closing of pipes (GH-151983) (#154172)
gh-119710: fix asyncio Process.wait() to finish on process exit and not wait for closing of pipes (GH-151983)
(cherry picked from commit f252132)
Co-authored-by: Tobias Alex-Petersen <tobias.alex.petersen@gmail.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
kumaraditya303 added a commit that referenced this pull request Jul 20, 2026
…t and not wait for closing of pipes (GH-151983) (#154171)
gh-119710: fix asyncio Process.wait() to finish on process exit and not wait for closing of pipes (GH-151983)
(cherry picked from commit f252132)
Co-authored-by: Tobias Alex-Petersen <tobias.alex.petersen@gmail.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
kumaraditya303 added a commit that referenced this pull request Jul 20, 2026
…t and not wait for closing of pipes (GH-151983) (#154170)
* gh-119710: fix asyncio Process.wait() to finish on process exit and not wait for closing of pipes (GH-151983)
(cherry picked from commit f252132)
Co-authored-by: Tobias Alex-Petersen <tobias.alex.petersen@gmail.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@tapetersen@kumaraditya303