【发布时间】:2008-09-17 08:05:18
【问题描述】:
如您所见,即使在程序本应死去之后,它也会从坟墓中说话。有没有办法在出现异常时“注销”exitfunction?
import atexit
def helloworld():
print("Hello World!")
atexit.register(helloworld)
raise Exception("Good bye cruel world!")
输出
Traceback (most recent call last):
File "test.py", line 8, in <module>
raise Exception("Good bye cruel world!")
Exception: Good bye cruel world!
Hello World!
【问题讨论】: