简体   繁体   English

使用Pdb进行Python调试

[英]Python Debugging Using Pdb

I'm using a interactive graphical Python debugger with ipdb under the hood (Canopy's graphical debugger). 我正在使用带有ipdb的交互式图形Python调试器(Canopy的图形化调试器)。 The script I am working on has multiple imported modules and several calls to their respective functions. 我正在处理的脚本有多个导入的模块和几个调用它们各自的功能。 Whenever I attempt a debugging run, execution gets stuck somewhere within a call to an imported module's function (specifically subprocess). 每当我尝试调试运行时,执行就会在对导入模块的函数(特别是子进程)的调用中卡住。 My two main questions are: 我的两个主要问题是:

1) Does running in debug mode slow things down considerably? 1)在调试模式下运行会大大减慢速度吗? Is the code not actually stuck, but just running at a painfully slow rate? 代码实际上是不是卡住了,而只是以一种非常缓慢的速度运行?

2) Is there a way to completely pass over bits of code and run them as if I were not even debugging? 2)有没有办法完全传递代码并运行它们就好像我甚至没有调试一样? I want to prevent the debugger from diving into subprocess and just execute it as if it were a normal run. 我想阻止调试器进入子进程,只是执行它就像正常运行一样。

I might toss the graphical debugger and do everything from a terminal, but I would like to avoid that if I can because the graphical interface is really convenient and saves a lot of typing. 我可能会抛弃图形化调试器,并从终端做所有事情,但我想避免这种情况,因为图形界面非常方便,节省了很多打字。

import pdb
a = "aaa"
pdb.set_trace()
b = "bbb"
c = "ccc"
final = a + b + c
print final

Your output when you run the code then it will start debugging and control will stop after a="aaa" 运行代码时输出然后它将开始调试并且在a="aaa"之后控制将停止

$ python abc.py
(Pdb) p a
'aaa'
(Pdb)

Thanks, Shashi 谢谢,Shashi

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM