Python atexit Module
Example
Register a function that runs when the program exits:
import atexit
def bye():
print("Goodbye!")
atexit.register(bye)
Try it Yourself »
Definition and Usage
The atexit
module lets you register callback functions to be invoked at normal interpreter termination.
Use it to run cleanup code, flush logs, or release resources in a predictable way when a program exits.
Members
Member | Description |
---|---|
register() | Register a function to be called at program exit. |
unregister() | Unregister a previously registered exit function. |