=== atexit 模塊=== (用於2.0版本及以上) ``atexit`` 模塊允許你注冊一個或多個終止函數(暫且這么叫), 這些函數將在解釋器終止前被自動調用. 調用 ``register`` 函數, 便可以將函數注冊為終止函數, 如 [Example 1-78 #eg-1-78] 所示. 你也可以添加更多的參數, 這些將作為 ``exit`` 函數的參數傳遞. ====Example 1-78. 使用 atexit 模塊====[eg-1-78] ``` File: atexit-example-1.py import atexit def exit(*args): print "exit", args # register two exit handler atexit.register(exit) atexit.register(exit, 1) atexit.register(exit, "hello", "world") *B*exit ('hello', 'world') exit (1,) exit ()*b* ``` 該模塊其實是一個對 ``sys.exitfunc`` 鈎子( hook )的簡單封裝.