how to disable pdb.set_trace() without stopping py

2019-05-07 14:15发布

问题:

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.



标签: python pdb