如何保存用于 pdb.post_mortem 的回溯
https://docs.pypython.org/3/library/tracebackback。 html#module-traceback :
模块使用追溯对象 - 这是存储在sys.last_traceback变量中的对象类型,并从sys.exc_info()返回为第三个项目
https://docs.python.org/3/library/traceback.html#trace.html#trace.extrack.extrack.stack_stack :
trackback.extrack_stack(f = none,limit = none) 从当前堆栈框架中提取原始追溯。返回值的格式与extract_tb()相同。可选的f和limit参数具有与print_stack()的含义相同的含义。
https:///docs.python.org/3/library/pdb。 html#pdb.post_mortem pdb.post_mortem(trackback = none)
输入给定追溯对象的事后调试。如果没有回溯,它使用当前正在处理的例外之一(如果要使用默认值,则必须处理一个例外)。
但是
import traceback
import pdb
try:
1/0
except Exception:
t = traceback.extract_stack()
<buncha other stuff>
pdb.post_mortem(t)
不起作用,因为trackback.extrack_stack()
返回stacksummary
pdb
无法处理的对象。
https://docs.python.org/3/library/traceback.html#module-traceback:
The module uses traceback objects — this is the object type that is stored in the sys.last_traceback variable and returned as the third item from sys.exc_info()
https://docs.python.org/3/library/traceback.html#traceback.extract_stack:
traceback.extract_stack(f=None, limit=None)
Extract the raw traceback from the current stack frame. The return value has the same format as for extract_tb(). The optional f and limit arguments have the same meaning as for print_stack().
https://docs.python.org/3/library/pdb.html#pdb.post_mortem pdb.post_mortem(traceback=None)
Enter post-mortem debugging of the given traceback object. If no traceback is given, it uses the one of the exception that is currently being handled (an exception must be being handled if the default is to be used).
yet
import traceback
import pdb
try:
1/0
except Exception:
t = traceback.extract_stack()
<buncha other stuff>
pdb.post_mortem(t)
doesn't work because traceback.extract_stack()
returns a StackSummary
object that pdb
can't handle.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请改用
t = sys.exc_info()[2]
。Use
t = sys.exc_info()[2]
instead.