首页 > 编程 > Python > 正文

Python atexit

2019-11-06 08:02:38
字体:
来源:转载
供稿:网友

atexit 模块用于注册解释器退出时执行的函数。该模块只有一个方法:

register(func [, args [, kwargs]])

将函数func添加到解释器退出时要执行的函数列表中。函数以fun(*args, **kwargs)的形式被调用。

In [1]: import atexitIn [2]: def fun(): ...: PRint "exit Interpreter" ...: In [3]: atexit.register(fun)Out[3]: <function __main__.fun>In [4]: Do you really want to exit ([y]/n)? yexit Interpreter

如果有多个函数注册,按注册顺序的逆序调用。


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表