如何保存用于 pdb.post_mortem 的回溯

发布于 2025-01-19 17:34:41 字数 1333 浏览 5 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

若能看破又如何 2025-01-26 17:34:41

请改用 t = sys.exc_info()[2]

Use t = sys.exc_info()[2] instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文