atexit
— 退出处理程序
¶
The
atexit
模块定义用于注册和取消注册清理函数的函数。因此,会自动执行注册函数当解释器正常终止时。
atexit
运行这些函数按
reverse
次序当注册它们时;若注册
A
,
B
,和
C
,解释器终止时,运行它们将按次序
C
,
B
,
A
.
注意:
The functions registered via this module are not called when the program is killed by a signal not handled by Python, when a Python fatal internal error is detected, or when
os._exit()
被调用。
注意: The effect of registering or unregistering functions from within a cleanup function is undefined.
3.7 版改变: When used with C-API subinterpreters, registered functions are local to the interpreter they were registered in.