gpt4 book ai didi

python - 如何获取 __del__ 中发生的异常的堆栈跟踪?

转载 作者:行者123 更新时间:2023-11-30 22:57:19 24 4
gpt4 key购买 nike

是否有一种简单的方法可以打印 __del__ 中发生的异常的堆栈跟踪?就我而言,没有为此对象定义 __del__ 方法

Exception TypeError: "'NoneType' object is not callable" in <bound method InteractiveSession.__del__ of <tensorflow.python.client.session.InteractiveSession object at 0x2867710>> ignored

最佳答案

您必须在 __del__ 中手动检测错误:

def __del__(self):
try:
cleanup()
except Exception:
import traceback
traceback.print_exc()

# Let the error keep propagating.
raise

无法配置 Python 对 __del__ 引发的异常执行的操作。这是direct callPyErr_WriteUnraisable ,没有地方提供回调,没有配置可以打印堆栈跟踪,之后也没有地方检索异常信息。

关于python - 如何获取 __del__ 中发生的异常的堆栈跟踪?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36730971/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com