atexit - Exit handlers

Page content
  • It performs cleanup after the interpreter exits.
  • It has two functions:

1. register()

  • It takes a function as an argument to be executed when the interpreter exits. Execution takes place on a LIFO.
""" Output: Goodbye
from atexit import register

def goodbye():

2. unregister()

  • After calling unregister(), <function_name> is guaranteed not to be called when the interpreter shuts down, even if it was registered more than once.
"""Output: No output
from atexit import unregister

names = ['Bob', 'Mike', 'Alice']
def hello(name):
for name in names: