Question

I have recently come across a VERY cool Python module called pdb. For those that are not familiar with it, it is super easy to use and gives you access to pretty much anything within scope at the time. All you have to do to use it is import pdb and put this line in your program where you want to set the breakpoint:

pdb.set_trace()

It works very much like gdb, and I wouldnt be surprised if it was built on top to some extent. Anyway, what I would like to know:

Say I have stopped at my first breakpoint, evaluated some things, and now I want to finish my program. How can I tell the debugger to finish the program, WITHOUT stopping at any more breakpoints? There are some commands, like continue, step, and next, but none of these seem to run the rest of the program uninterrupted. Anyone have some experience with this or am I asking for something that doesnt exist? Thanks!

Was it helpful?

Solution

I would just override pdb.set_trace function, delete all breakpoints and continue

pdb.set_trace = lambda : 0

The good thing is that you can do monkey patching in the debugger.

vikasdhi@redpanda:~$ cat ~/tmp/test.py
for i in range(1000):
    import pdb
    pdb.set_trace()
vikasdhi@redpanda:~$ python ~/tmp/test.py
> /home/vikasdhi/tmp/test.py(1)<module>()
-> for i in range(1000):

it stopped for the first time

(Pdb) c
> /home/vikasdhi/tmp/test.py(1)<module>()
-> for i in range(1000):
(Pdb) c
> /home/vikasdhi/tmp/test.py(1)<module>()
-> for i in range(1000):

when i want to skip everything i just replace the function

(Pdb) pdb.set_trace = lambda : 0
(Pdb) c
vikasdhi@redpanda:~$ 

OTHER TIPS

the command is cl or clear.

cl(ear) [filename:lineno | bpnumber [bpnumber ...]]

With a filename:lineno argument, clear all the breakpoints at this line. With a space separated list of breakpoint numbers, clear those breakpoints. Without argument, clear all breaks (but first ask confirmation).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top