You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
forked process in multiprocessing does not honour atexit #83856
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee='https://github.com/pablogsal'closed_at=Nonecreated_at=<Date2020-02-18.11:35:55.954>labels= ['type-bug', 'library', '3.9']
title='forked process in multiprocessing does not honour atexit'updated_at=<Date2020-02-18.12:27:31.963>user='https://github.com/gaborbernat'
In case of a forked process childs the atexit is never executed (note it works if I ran them manually at the end of the child process; so they're registered correctly). Switching to spawn method makes it work as expected. The behaviour is the same even if you call register within the child process (as opposed to being inherited during forking). Also found this StackOverflow question that mentions this https://stackoverflow.com/a/26476585. At the very least the documentation should explain this; though I'd expect atexit to be called before finalization of the fork processes (assuming the child process exits with 0 exit code). d
The discussion on the PR was useful. This is merged in time for 3.13beta1. It is a bit of a behavior change and a corner case that has existed for a long time and most code does not hit so I do not believe we should be backporting it as a bugfix despite it also being reasonably to call a bug. Thanks for the discussion and PR!
Activity
gaborbernat commentedon Feb 18, 2020
I've talked with Pablo about this in person, and as advised opening the issue here now.
I've discovered that forked processes do not honour atexit registrations. See the following example code:
In case of a forked process childs the atexit is never executed (note it works if I ran them manually at the end of the child process; so they're registered correctly). Switching to spawn method makes it work as expected. The behaviour is the same even if you call register within the child process (as opposed to being inherited during forking). Also found this StackOverflow question that mentions this https://stackoverflow.com/a/26476585. At the very least the documentation should explain this; though I'd expect atexit to be called before finalization of the fork processes (assuming the child process exits with 0 exit code). d
pablogsal commentedon Jan 19, 2024
CC: @gpshead @pitrou @ambv
See the PR and this comment for more context
gh-83856: Honor atexit for all multiprocessing start methods (GH-114279)
gpshead commentedon May 3, 2024
The discussion on the PR was useful. This is merged in time for 3.13beta1. It is a bit of a behavior change and a corner case that has existed for a long time and most code does not hit so I do not believe we should be backporting it as a bugfix despite it also being reasonably to call a bug. Thanks for the discussion and PR!
pythongh-83856: Honor atexit for all multiprocessing start methods (p…