atexit.register()
atexit.register() is a Python function in the Atexit Module category. Registers a function to be called at program exit (like cleanup). The syntax is atexit.register(func, *args, **kwargs). Parameters: func, *args. Returns: func (for use as decorator). A typical example: import atexit
def cleanup():
print("Cleaning up...")
atexit.register(cleanup)
# Also works as a decorator:
@atexit.register
def goodbye():
print("Goodbye!"). A close sibling is atexit.unregister(), which removes a function from the list of exit handlers. A close sibling is atexit._clear(), which clears all registered exit handlers. More about this category: Exit handlers — register, unregister. Related Atexit Module entries: atexit.unregister(), atexit._clear(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details. You can try atexit.register() immediately in the Python playground, look up unfamiliar terms in the glossary, or return to the Python Reference homepage.