Repository navigation
gh-158287: Fix blocked asyncio event loop on macOS when child process is stopped - #158962
Open
JohnnyWilson16 wants to merge 5 commits into
Open
JohnnyWilson16 wants to merge 5 commits into
JohnnyWilson16 wants to merge 5 commits into
Conversation
…rocess is stopped On macOS, waitid(os.P_PID, pid, os.WEXITED | os.WNOWAIT) returns on SIGSTOP with si_code == CLD_STOPPED even though WSTOPPED was not requested. In _ThreadedChildWatcher, consume the stop notification and continue waiting for actual process termination rather than calling _reap_and_notify with os.waitpid(pid, 0) which blocks the event loop thread.
JohnnyWilson16
requested review from
1st1,
asvetlov,
kumaraditya303 and
willingc
as code owners
October 7, 2026 12:04
2 tasks done
deadlovelll
reviewed
Oct 9, 2026
deadlovelll
reviewed
Oct 9, 2026
deadlovelll
reviewed
Oct 9, 2026
deadlovelll
reviewed
Oct 9, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes gh-158287.
On macOS (Darwin),
os.waitid(os.P_PID, expected_pid, os.WEXITED | os.WNOWAIT)unexpectedly returns when a child process is stopped (SIGSTOP), reportingsi_code == CLD_STOPPEDdespiteWSTOPPEDnot being requested (a known Darwin kernel quirk, also observed in dotnet/runtime#133930).In
_ThreadedChildWatcher._do_waitpid, treating this as process exit schedules_reap_and_notify, whereos.waitpid(expected_pid, 0)blocks the main event loop thread indefinitely because the child has not terminated.This change consumes the stop notification via
waitid(os.P_PID, expected_pid, consume_flags)and continues waiting until actual process termination. Also adds a regression test toSubprocessThreadedWatcherTests.