简体   繁体   English

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

[英]How to debug ignored exception in python

I got a lot of ignored exceptions when my (python 2.7) program exits. 我的(python 2.7)程序退出时,我遇到了很多被忽略的异常。 But since the project scale is large, and based on a project developed by others, it's hard to locate the bug with such info. 但是由于项目规模很大,并且基于其他人开发的项目,因此很难使用此类信息来定位错误。 Is there any way to get the exception trace, or any other methods that can help? 有没有什么方法可以获取异常跟踪,或者任何其他可以帮助您的方法? Thanks. 谢谢。

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

您可以运行:

$ python -v your_file.py

I would scan the codebase for strings that match the output. 我将在代码库中扫描与输出匹配的字符串。 Something like Exception .* ignored as the exception and object information are likely to be formatting variables. Exception .* ignored类的东西Exception .* ignored因为异常和对象信息可能正在格式化变量。 This should find the statements that generate the output. 这应该找到生成输出的语句。

Once you have found these statements, assuming that they are inside a try / except block you can use the tools in the traceback module to print the tracebacks, or, if the logging package is being used, pass the keyword argument exc_info=True to the log method . 找到这些语句后,假设它们位于try / except块内,则可以使用traceback模块中的工具打印回溯,或者,如果正在使用日志记录包,则将关键字参数exc_info=True传递给日志方法

It's also worth scanning to see if sys.excepthook is being overridden. 还值得扫描以查看sys.excepthook是否被覆盖。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM