PDB:在控制台中时出现异常 - 完整堆栈跟踪
在 pdb 控制台中,输入导致异常的语句只会导致单行堆栈跟踪,例如,
(Pdb) someFunc()
*** TypeError: __init__() takes exactly 2 arguments (1 given)
但是我想找出 someFunc
中错误的确切来源。即在这种情况下,__init__
附加到哪个类。
有没有办法在 Pdb 中获取完整的堆栈跟踪?
When at the pdb console, entering a statement which causes an exception results in just a single line stack trace, e.g.
(Pdb) someFunc()
*** TypeError: __init__() takes exactly 2 arguments (1 given)
However I'd like to figure out where exactly in someFunc
the error originates. i.e. in this case, which class __init__
is attached to.
Is there a way to get a full stack trace in Pdb?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是在代码中定义一个函数,调用 someFunc() 并打印回溯,然后从 Pdb 调用该函数。
或者,您可以自己打印回溯。给定这个源代码:
那么我们可以这样做:
The easiest way would be to define a function in your code that calls someFunc() and prints the traceback then call that from Pdb.
Alternatively you can print the traceback for yourself. Given this source code:
Then we can do this:
pdb
支持递归调用的debug
语句:pdb
supportsdebug
statements for recursive invocation: