The atexit Module

(2.0 only) The atexit 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, as shown in Example 1-78. You can also add one or more extra arguments, which are passed as arguments to the exit function.

Example 1-78. Using the atexit Module


import atexit

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

# register two exit handler
atexit.register(exit, 1)
atexit.register(exit, "hello", "world")

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

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

Core Modules

More Standard Modules

Threads and Processes

Data Representation

File Formats

Mail and News Message Processing

Network Protocols


Multimedia Modules

Data Storage

Tools and Utilities

Platform-Specific Modules

Implementation Support Modules

Other Modules

Python Standard Library
Python Standard Library (Nutshell Handbooks) with
ISBN: 0596000960
EAN: 2147483647
Year: 2000
Pages: 252
Authors: Fredrik Lundh Ā© 2008-2020.
If you may any questions please contact us: