如何调试python中被忽略的异常

2024-04-19 16:06:43 发布

您现在位置:Python中文网/ 问答频道 /正文

当我的(python2.7)程序退出时,有很多被忽略的异常。但是由于项目规模很大,而且基于他人开发的项目,很难用这样的信息来定位bug。有没有什么方法可以获取异常跟踪,或者其他方法可以帮助您?谢谢。你知道吗

Exception TypeError: "'NoneType' object is not callable" in <object repr() failed> ignored
Exception TypeError: "'NoneType' object is not callable" in <object repr() failed> ignored
Exception TypeError: "'NoneType' object is not callable" in <object repr() failed> ignored
...
Exception TypeError: "'NoneType' object is not callable" in <object repr() failed> ignored

Tags: 项目方法in程序objectisexceptionnot
2条回答

您可以运行:

$ python -v your_file.py

我会扫描代码库中与输出匹配的字符串。像Exception .* ignored这样的异常和对象信息很可能是格式化变量。这应该找到生成输出的语句。你知道吗

一旦找到这些语句,假设它们位于try/except块中,就可以使用traceback模块中的工具打印回溯,或者,如果正在使用logging包,则将关键字参数exc_info=True传递给日志method。你知道吗

还值得扫描一下sys.excepthook是否被覆盖。你知道吗

相关问题 更多 >