how to disable pdb.set_trace() without stopping python program and edit the code

耗尽温柔 提交于 2019-12-10 04:26:45

问题


I suspect that I have issue in one of my loops, so I setup a break points with pdb.set_trace()

import pdb
for i in range(100):
    print("a")
    pdb.set_trace()
    print("b")

after check variable in this loop for a few times, I decide continue this programming without further breaks. So I try to get the break number with b command, no breaks listed. I guess this line of code don't setup a break point. but How Do I get ride of this "break points" without stopping the program and change the code?


回答1:


to my knowledge, you could not bypass set_trace, but you could neutralize it, once debugger stopped, type:

pdb.set_trace = lambda: 1

then continue, it wont break again.




回答2:


Unfortunately pdb is missing a bunch of functionality (even basic stuff like display lists), and you've found another example of that here. The good news is that pdb++ 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()

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



来源:https://stackoverflow.com/questions/46166539/how-to-disable-pdb-set-trace-without-stopping-python-program-and-edit-the-code

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!