This module defines functions to register and unregister cleanup functions. Functions thus registered are automatically executed upon normal vm termination.
These functions are run in the reverse order in which they were registered;
if you register
C, they will be run in the order
Available on these boards
- atexit.register(func: Callable[Ellipsis, Any], *args: Optional[Any], **kwargs: Optional[Any]) Callable[Ellipsis, Any] ¶
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
register(). It is possible to register the same function and arguments more than once.
At normal program termination (for instance, if
sys.exit()is called or the vm execution completes), all functions registered are called in last in, first out order.
If an exception is raised during execution of the exit handler, a traceback is printed (unless
SystemExitis raised) and the execution stops.
This function returns func, which makes it possible to use it as a decorator.
- atexit.unregister(func: Callable[Ellipsis, Any]) None ¶
Remove func from the list of functions to be run at termination.
unregister()silently does nothing if func was not previously registered. If func has been registered more than once, every occurrence of that function in the atexit call stack will be removed.