mirror of
https://github.com/python/cpython.git
synced 2025-11-27 05:44:16 +00:00
Improve doc for atexit.register and unregister (#12297)
This commit is contained in:
parent
b2f5c0a4c4
commit
ccddc474c3
1 changed files with 9 additions and 8 deletions
|
|
@ -22,7 +22,8 @@ is detected, or when :func:`os._exit` is called.
|
||||||
|
|
||||||
Register *func* as a function to be executed at termination. Any optional
|
Register *func* as a function to be executed at termination. Any optional
|
||||||
arguments that are to be passed to *func* must be passed as arguments to
|
arguments that are to be passed to *func* must be passed as arguments to
|
||||||
:func:`register`.
|
:func:`register`. It is possible to register the same function and arguments
|
||||||
|
more than once.
|
||||||
|
|
||||||
At normal program termination (for instance, if :func:`sys.exit` is called or
|
At normal program termination (for instance, if :func:`sys.exit` is called or
|
||||||
the main module's execution completes), all functions registered are called in
|
the main module's execution completes), all functions registered are called in
|
||||||
|
|
@ -35,15 +36,17 @@ is detected, or when :func:`os._exit` is called.
|
||||||
saved. After all exit handlers have had a chance to run the last exception to
|
saved. After all exit handlers have had a chance to run the last exception to
|
||||||
be raised is re-raised.
|
be raised is re-raised.
|
||||||
|
|
||||||
This function returns *func* which makes it possible to use it as a decorator
|
This function returns *func*, which makes it possible to use it as a
|
||||||
without binding the original name to ``None``.
|
decorator.
|
||||||
|
|
||||||
|
|
||||||
.. function:: unregister(func)
|
.. function:: unregister(func)
|
||||||
|
|
||||||
Remove a function *func* from the list of functions to be run at interpreter-
|
Remove *func* from the list of functions to be run at interpreter
|
||||||
shutdown. After calling :func:`unregister`, *func* is guaranteed not to be
|
shutdown. After calling :func:`unregister`, *func* is guaranteed not to be
|
||||||
called when the interpreter shuts down.
|
called when the interpreter shuts down, even if it was registered more than
|
||||||
|
once. :func:`unregister` silently does nothing if *func* was not previously
|
||||||
|
registered.
|
||||||
|
|
||||||
|
|
||||||
.. seealso::
|
.. seealso::
|
||||||
|
|
@ -98,6 +101,4 @@ Usage as a :term:`decorator`::
|
||||||
def goodbye():
|
def goodbye():
|
||||||
print("You are now leaving the Python sector.")
|
print("You are now leaving the Python sector.")
|
||||||
|
|
||||||
This obviously only works with functions that don't take arguments.
|
This only works with functions that can be called without arguments.
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue