gh-144766: Fix flaky test_trampoline_works_with_forks#148056
Open
yonatan-genai wants to merge 3 commits intopython:mainfrom
Open
gh-144766: Fix flaky test_trampoline_works_with_forks#148056yonatan-genai wants to merge 3 commits intopython:mainfrom
yonatan-genai wants to merge 3 commits intopython:mainfrom
Conversation
The fork child ran full Python finalization instead of calling os._exit(0), which is fragile when perf trampoline support is active (unmapping executable memory and unregistering code watchers during finalization can crash intermittently). The newer test added in the same file (test_trampoline_works_after_fork_with_many_code_objects) already uses os._exit(0) for this reason. Also fix the parent's wait status handling: os.waitpid returns a raw wait status, not an exit code. Use os.WEXITSTATUS to extract the actual exit code, and check os.WIFSIGNALED for signal deaths. <claude>
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
os._exit() does not flush Python IO buffers, so the print(os.getpid()) output was lost when stdout is piped. Add flush=True to ensure the child PID reaches the parent. Also add the required NEWS entry. <claude>
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.
Summary
test_trampoline_works_with_forksintermittently fails on macOS CI because the fork child runs full Python finalization instead of callingos._exit(0). Perf trampoline finalization in a forked child is fragile: it unmaps executable memory and unregisters code watchers while code objects are being destroyed, which can crash intermittently.The newer test in the same file (
test_trampoline_works_after_fork_with_many_code_objects, added in gh-144766) already usesos._exit(0)in the child for exactly this reason. This applies the same pattern to the older test.Also fixes the parent's wait status handling:
os.waitpidreturns a raw 16-bit wait status, not an exit code. The old code passed this raw status tosys.exit(), which could produce incorrect exit codes. Now usesos.WEXITSTATUS()to extract the actual exit code andos.WIFSIGNALED()to detect signal deaths.Changes
Lib/test/test_perf_profiler.py: Addos._exit(0)in fork child, fix wait status handling in parentDiscovered while testing #148050 (unrelated multiprocessing change that was blocked by this flaky test on macOS CI).