调试python时调用Bdbquit [英] Bdbquit raised when debugging python
问题描述
追溯(最近的呼叫最后):
文件/Users/isaachess/Programming/vivint/Platform/MessageProcessing/vivint_cloud/queues/connectors/amqplib_connector.py,第191行,在acking_callback
回调(message.body)
文件/Users/isaachess/Programming/vivint/Platform/MessageProcessing/vivint_cloud/queues/consumable_message_queue.py,第32行,deserialized_callback
self._callback_method(msg)
文件/ Users / isaachess / Programming / vivint / Platform / BusinessLogic / businesslogic / util / statsd_util.py,第95行,_time_func
retVal = f(* args,** kwargs)
文件/ Users / isaachess /程序/ vivint / Platform / MessageProcessing / vivint_cloud / net / router.py,第226行,处理
try:
文件/ Users / isaachess / Programming / vivint / Platform / MessageProcessing / vivint_cloud / net /router.py,第226行,处理
try:
文件/ System / L ibrary / Frameworks / Python.framework / Versions / 2.7 / lib / python2.7 / bdb.py,第49行,trace_dispatch
return self.dispatch_line(frame)
文件/ System / Library /框架/ Python.framework /版本/ 2.7 / lib / python2.7 / bdb.py,第68行,dispatch_line
如果self.quitting:raise BdbQuit
BdbQuit
这是插入行之后:
import pdb代码中的pdb.set_trace()
我无法弄清楚为什么会发生这种情况。我已经阅读了Bdb和Bdbquit,但是不能弄清楚为什么在我的代码中会发生这种情况。任何人都可以提供一些为什么会发生这种情况的提示?我真的想让调试器再次工作。
如果从(pdb)
提示符,并允许您的代码正常完成,我不会期望输出像你指示的追溯,但如果你退出 pdb
,使用退出
命令或^ D(EOF),因为没有什么可以捕获 BdbQuit $ c调试器退出时引发$ c>异常。在
bdb.py
self.quitting
设置为 True
在各种情况下,导致提升BdbQuit
,以及典型的除了
是一个简单的 BdbQuit的
子句 pass
语句。看来 pdb
从 bdb
继承所有这些。
完全避免回溯的一种方法是使用 pdb
不同。而不是从你的代码调用 pdb.set_trace()
(而不是处理 BdbQuit
),你可以调用你的代码在 pdb
(而不是反之亦然)中,此时$ code> BdbQuit 异常将按照pdb的预期进行处理。这也将允许您选择断点位置,而无需修改代码(使用 pdb
的 break
命令)。或者你可以混合这两种方法;在 pdb
, pdb.set_trace()
调用和所有的代码下运行代码,那些调用将是您可以的断点只需修改代码即可删除。
您可以使用 c
中的代码调用> pdb 命令,您的脚本调用作为其命令行参数,或使用 python -m pdb
。
Recently when adding the debugger to my python 2.7.10 code, I get this message:
Traceback (most recent call last):
File "/Users/isaachess/Programming/vivint/Platform/MessageProcessing/vivint_cloud/queues/connectors/amqplib_connector.py", line 191, in acking_callback
callback(message.body)
File "/Users/isaachess/Programming/vivint/Platform/MessageProcessing/vivint_cloud/queues/consumable_message_queue.py", line 32, in deserialized_callback
self._callback_method(msg)
File "/Users/isaachess/Programming/vivint/Platform/BusinessLogic/businesslogic/util/statsd_util.py", line 95, in _time_func
retVal = f(*args, **kwargs)
File "/Users/isaachess/Programming/vivint/Platform/MessageProcessing/vivint_cloud/net/router.py", line 226, in handle
try:
File "/Users/isaachess/Programming/vivint/Platform/MessageProcessing/vivint_cloud/net/router.py", line 226, in handle
try:
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/bdb.py", line 49, in trace_dispatch
return self.dispatch_line(frame)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/bdb.py", line 68, in dispatch_line
if self.quitting: raise BdbQuit
BdbQuit
This is after inserting the lines:
import pdb; pdb.set_trace()
in the code.
I cannot figure out why this is happening. I've read up on Bdb and Bdbquit, but cannot figure out why this is happening in my code. Can anyone provide me with some hints of why this happens in general? I really want to get the debugger working again.
If you continue from the (pdb)
prompt and allow your code to finish normally, I wouldn't expect output like the traceback you indicated, but if you quit pdb
, with the quit
command or ^D (EOF), a traceback like that occurs because there is nothing to catch the BdbQuit
exception raised when the debugger quits. In bdb.py
self.quitting
gets set to True
in various circumstances, which leads to raise BdbQuit
, and the typical except:
clause for BdbQuit
is a simple pass
statement. It appears that pdb
inherits all of that from bdb
.
One way to avoid that traceback altogether is to use pdb
differently. Rather than calling pdb.set_trace()
from your code (and not handling BdbQuit
at all), you can invoke your code within pdb
(rather than vice versa), at which point the BdbQuit
exception will be handled as intended by pdb. That will also allow you to choose breakpoint locations without modifying your code (using pdb
's break
command). Or you can mix the two approaches; run your code under pdb
, pdb.set_trace()
calls and all, and those calls will be breakpoints that you can remove only by modifying your code.
You can invoke your code within pdb
by using the pdb
command with your script invocation as its command line arguments, or with python -m pdb
.
这篇关于调试python时调用Bdbquit的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!