简体   繁体   English

如何在python关闭时调试异常

[英]How do a debug an exception on python shutdown

When my process ends, I get output to stderr that looks like: 当我的进程结束时,我得到输出到stderr,看起来像:

  Exception exceptions.TypeError: "'NoneType' object is not callable" in <function <lambda> at 0x5507d70> ignored

My understanding is that this is caused by exceptions being generated during garbage collection ( del () ?) or the weakref callback which I know is being used in this application. 我的理解是,这是由垃圾收集( del ()?)中生成的异常或我知道在此应用程序中使用的weakref回调引起的。

What are some methods for finding out where this is coming from ? 有哪些方法可以找出它的来源?

Run your Python program with the -v option so you can see at which point during the final stages the exception gets thrown. 使用-v选项运行Python程序,以便在最后阶段的哪个阶段看到抛出异常。 It helped me when I encountered the same situation; 当我遇到同样的情况时,它帮助了我; also with sqlalchemy... 还有sqlalchemy ......

The issue here isn't with lambdas: lambda functions do have debug information. 这里的问题不在于lambdas:lambda函数确实有调试信息。

a = lambda: 1
print a.func_code.co_filename
print a.func_code.co_firstlineno

( a.__code__ in python3.) (python3中的a.__code__ 。)

The problem is with the fallback exception formatting: it's not showing a stack trace, which is where this information is normally shown. 问题在于回退异常格式化:它没有显示堆栈跟踪,这是通常显示此信息的位置。

If you want to try to improve this, the problem seems to be in Python/errors.c, in PyErr_WriteUnraisable(). 如果你想尝试改进这个,那么问题似乎是在Python / errors.c中,在PyErr_WriteUnraisable()中。 I don't know if there are any deeper issues making this difficult, but I suspect not. 我不知道是否有任何更深层次的问题使这很困难,但我怀疑不是。 The traceback should be in "tb" after PyErr_Fetch() is called. 调用PyErr_Fetch()后,回溯应该在“tb”中。

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

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