我希望在正常退出时完全关闭执行一个任务的类,而不是在类似exit(1)的情况下。如何确定当前退出代码。示例:
import sys
import atexit
def myexit():
print("atexit")
atexit.register(myexit)
class Test(object):
def __init(self):
pass
def __del__(self):
print("here")
# print(sys.exit_code) # How do I get this???
x = Test()
exit(1)
产生:
atexit
here
但在这两个地方,我都不知道如何将退出代码传递给sys.exit()
有other answer 但是,从另一个实现强制包装似乎并不明智 可重用模块
目前没有回答
相关问题 更多 >
编程相关推荐