Reword atexit docs - #156086
Conversation
For the `atexit` module: - Move common info from `register` to the module level (a lot of this was duplicated -- less maintainable and harder to read) - Use *interpreter shutdown* consistently, introducing it as a more general term for the old docs' "program termination". - Use consistent terminology (exit handlers) - Move warning for a mitigated footgun to a change entry - Add a new warning about keeping things usable Similarly clarify docs for the `atexit` attribute in `weakref`.
Documentation build overview
|
| **Note:** The effect of registering or unregistering functions from within | ||
| a cleanup function is undefined. |
There was a problem hiding this comment.
This is defined starting in 3.15; Python will run any handlers that have been added.
There was a problem hiding this comment.
Hmm, really?
import atexit
atexit.register(print, 'run me!')
@atexit.register
def foo():
atexit.register(print, 'run me too!')$ python3.15 /tmp/demo.py
run me!In any case, should we guarantee that? What about unregistering?
Sounds like material for a follow-up that's not backported to 3.14.
There was a problem hiding this comment.
Well, it works as documented -- and better than an infinite loop with a function registering itself...
| Attempts to start a new thread or :func:`os.fork` a new process | ||
| in an exit handler now leads to :exc:`RuntimeError`. | ||
| Previously, this could cause race conditions between the main Python | ||
| runtime thread freeing thread states while internal :mod:`threading` |
There was a problem hiding this comment.
Link to the term here?
| runtime thread freeing thread states while internal :mod:`threading` | |
| runtime thread freeing :term:`thread states <thread state>` while internal :mod:`threading` |
There was a problem hiding this comment.
Clarifying which internals exactly cause your crash isn't too useful.
(I considered removing the details entirely, but kept them to illustrate the warning above.)
|
I'll merge ~Friday if there are no objections. |
|
Thanks @encukou for the PR 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15. |
|
GH-156878 is a backport of this pull request to the 3.15 branch. |
|
Sorry, @encukou, I could not cleanly backport this to |
|
GH-156879 is a backport of this pull request to the 3.14 branch. |
|
GH-156889 is a backport of this pull request to the 3.13 branch. |
For the `atexit` module: - Move common info from `register` to the module level (a lot of this was duplicated -- less maintainable and harder to read) - Use *interpreter shutdown* consistently, introducing it as a more general term for the old docs' *program termination*. - Use the term *exit handler* consistently - Move warning for a mitigated footgun to a change entry - Add a new warning about keeping things usable Similarly clarify docs for the `atexit` attribute in `weakref`. (cherry picked from commit 1d28836) Co-authored-by: Petr Viktorin <encukou@gmail.com>
For the
atexitmodule:registerto the module level (a lot of this was duplicated -- less maintainable and harder to read)Similarly clarify docs for the
atexitattribute inweakref.