-
-
Notifications
You must be signed in to change notification settings - Fork 30k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
execv (et al.) should invoke atexit handlers before executing new code #61026
Comments
If I register an atexit handler, and then call os.execv, the handler is not invoked before my process changes over to the new program. Shouldn't it be? My program is ending, so my atexit handlers should be invoked. This is based on this coverage.py bug: https://bitbucket.org/ned/coveragepy/issue/43/coverage-measurement-fails-on-code If the atexit handlers were invoked as part of os.execv, it would work properly. |
That's a good question. Conceptually it makes sense, but I wonder if programs currently rely on os.execv not cleaning up anything: not only it doesn't call atexit handlers, but it also doesn't try to shutdown the interpreter. Which can be handy if you are using exec() in a fork() + exec() context (I think it is generally recommended to use os._exit(), not sys.exit() in a forked child). |
FTR, with C's atexit(3), the handlers are not called either on exec(). |
The first reason for not calling atexit handlers upon exec() is that Note that the atexit documentation states that handlers will only be So I'm -1 on the change, the chance of breaking existing applications |
I agree with Charles-François, this is a too risky change. |
Couldn't coverage.py and similar apps can just invoke the atexit handlers before calling os.execv() or similar? If so, perhaps a mention of this in the docs would suffice? |
Coverage.py is registering a handler to save data before the program ends. The execv call is not in the coverage.py code, it's in the program that coverage.py is running. |
Seems like a decision needs to be made: Add support for |
Note that a common use case is that you actually want to replace the current process intentionally without any atexit handlers. So changing this now would break such cases. However, calling the atexit handlers explicitly when this is wanted should also be possible, so there should be a separate API for that. Also, this should ideally cover native atexit handlers, also uninit libraries etc, i.e. doing a proper shutdown of the process. Maybe this API can be combined with I have a use case for the latter: I want to restart my app. It uses CUDA. Just doing |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: