问题:如何退出pdb并允许程序继续?

我正在使用pdb模块调试程序。我想了解如何退出pdb并允许程序继续进行到完成。该程序的运行在计算上很昂贵,所以我不想在脚本未尝试完成的情况下退出。continue似乎不起作用。如何退出pdb并继续执行我的程序?

I’m using the pdb module to debug a program. I’d like to understand how I can exit pdb and allow the program to continue onward to completion. The program is computationally expensive to run, so I don’t want to exit without the script attempting to complete. continue doesn’t seems to work. How can I exit pdb and continue with my program?


回答 0

continue应该是“继续执行,只有在遇到断点时才停止”,这样您就在某个地方设置了断点。要删除断点(如果您是手动插入的):

(Pdb) break
Num Type         Disp Enb   Where
1   breakpoint   keep yes   at /path/to/test.py:5
(Pdb) clear 1
Deleted breakpoint 1
(Pdb) continue

或者,如果您正在使用pdb.set_trace(),则可以尝试执行此操作(尽管如果您以更花哨的方式使用pdb,则可能会导致问题……)

(Pdb) pdb.set_trace = lambda: None  # This replaces the set_trace() function!
(Pdb) continue
# No more breaks!

continue should “Continue execution, only stop when a breakpoint is encountered”, so you’ve got a breakpoint set somewhere. To remove the breakpoint (if you inserted it manually):

(Pdb) break
Num Type         Disp Enb   Where
1   breakpoint   keep yes   at /path/to/test.py:5
(Pdb) clear 1
Deleted breakpoint 1
(Pdb) continue

Or, if you’re using pdb.set_trace(), you can try this (although if you’re using pdb in more fancy ways, this may break things…)

(Pdb) pdb.set_trace = lambda: None  # This replaces the set_trace() function!
(Pdb) continue
# No more breaks!

回答 1

一个简单的CtrlD将突破pdb。如果要继续而不是中断,只需按c而不是整个continue命令

A simple CtrlD will break out of pdb. If you want to continue rather than breaking, just press c rather than the whole continue command


回答 2

@voithos 的答案是正确的,因此在您使用的情况下,我只会添加一个替代方法set_trace。是的,pdb.set_trace = lambda: None黑客程序可以正常运行,但是如果您设置了其他断点并希望稍后重新启用它,则不会。对我来说,这表明不幸的pdb是缺少了许多功能(甚至是基本的东西,如显示列表),这是另一种情况。

好消息是这是一个很好的替代产品pdb,它解决的问题之一就是禁用问题set_trace。因此,您可以简单地执行以下操作:

pip install pdbpp

然后在(Pdb++)提示符下键入:

pdb.disable()

如果您以后想要重新启用,那么这很正常:

pdb.enable()

简单!除此之外,您还将获得许多其他有用的东西。

The answer from @voithos is correct, so I’ll just add one alternative in the case where you are using set_trace. Yes, the pdb.set_trace = lambda: None hack works OK, but not if you have other breakpoints set and want to reenable it later on. To me this points to the fact that unfortunately pdb is missing a bunch of functionality (even basic stuff like display lists), and this is another case.

The good news is that is a great drop-in replacement for pdb, and one of the things it solves is exactly the problem of disabling set_trace. So you can simply do:

pip install pdbpp

and then at the (Pdb++) prompt, type:

pdb.disable()

If you want to reenable later, unsurprisingly this works:

pdb.enable()

Easy! And you will get lots of other useful goodies on top of that.


回答 3

如果您确实希望退出调试器,则需要运行WinPdb之类的程序,该程序可让您脱离进程,然后退出调试器(注意,它是多平台的)。

如果您想继续调试但不再在给定的断点处停止,则需要:

  1. 记下断点号(或文件和行号),
  2. 无论是cl bp_number clear file:line永久删除断点 disable pb_number切换它关闭,但可以切换回来。
  3. 然后continue,您的程序将运行,直到遇到下一个不同的断点为止。

有关上述内容的更多详细信息,请参见手册

If you really wish to exit the debugger then you need to run something like WinPdb which allows you to detach from the process and then exit the debugger, (N.B. It is multi-platform).

If you would like to continue debugging but no longer stop at a given breakpoint then you need to:

  1. Make a note of the breakpoint number, (or the file and line number),
  2. Either cl bp_number or clear file:line to permanently remove the breakpoint or disable pb_number to toggle it off but be able to toggle it back.
  3. Then continue and your program run until then next different breakpoint is hit.

For more detail on the above see the manual.


回答 4

找到不安装任何东西而退出pdb的新方法:-当程序开始运行时,按ctrl + c,然后将窗口切换到另一个(任何窗口),然后运行pdb的原始shell应该显示如下内容:(pdb) …..-切换回pdb,然后按Enter,现在一切就绪,pdb命令外壳再次出现

find new way to exit the pdb without install anything: – when the program starts to run, press ctrl+c, then switch the window to another(any window), then the original shell with pdb running should show something like: (pdb) ….. – switch back to pdb, then press Enter, now you are all set, pdb command shell reappear again


声明:本站所有文章,如无特殊说明或标注,均为本站原创发布。任何个人或组织,在未征得本站同意时,禁止复制、盗用、采集、发布本站内容到任何网站、书籍等各类媒体平台。如若本站内容侵犯了原著者的合法权益,可联系我们进行处理。