Prevent duplicate output in 3.14 #415
Open
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.
Fix Python 3.14.2 multiprocessing shutdown behavior by ensuring only the owner process registers the
atexitreporting hook.Problem
When running the complex example with
LINE_PROFILE=1andPROFILE_TYPE=expliciton Python 3.14.2, multiprocessing using theforkserverstart method can cause non-owner processes (e.g., the forkserver process / child processes) to also register theatexithook. At interpreter shutdown, those processes may try to print/write profiling results, resulting in:profile_output.txt,Root cause
atexit.register(...)was executed in processes that should not own reporting. Even ifshow()includes guards, shutdown ordering and partially-torn-down globals can make those guards unreliable. The safest approach is to avoid registering the hook outside the owner process.Fix
Move/guard
atexit.register(...)so it occurs only after establishing ownership (PID/parent/process role) and only in the designated owner process. Non-owner processes never register the shutdown reporter.The above is a GPT description of the patch, which I used heavily to find the problem. I believe the diagnosis is correct, but I don't understand what changed in 3.14.2 to cause the problem. Pushing up the patch as is to see if it fixes the dashboard.