The atexit module

(2.0 and newer) This module allows you to register one or more functions that are called when the interpreter is terminated.

To register a function, simply call the register function. You can also add one or more extra arguments, which are passed as arguments to the exit function.

Example: Using the atexit module
# File:

import atexit

def exit(*args):
    print "exit", args

# register three exit handlers
atexit.register(exit, 1)
atexit.register(exit, "hello", "world")

$ python
exit ('hello', 'world')
exit (1,)
exit ()

This module is a straightforward wrapper for the sys.exitfunc hook.


A Django site. rendered by a django application. hosted by webfaction.