Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python: in pdb is it possible to enable a breakpoint only after n hit counts?

In eclipse (and several other IDE's as well) there is an option to turn on the breakpoint only after a certain number of hits. In Python's pdb there is a hit count for breakpoints and there is the condition command. How do I connect them?

like image 720
zenpoy Avatar asked Jan 03 '13 13:01

zenpoy


People also ask

How do you set a breakpoint in Python pdb?

It's easy to set a breakpoint in Python code to i.e. inspect the contents of variables at a given line. Add import pdb; pdb. set_trace() at the corresponding line in the Python code and execute it. The execution will stop at the breakpoint.

Can you set breakpoints in Python?

Python Quick Tip: Debugger and breakpoint()You can insert a breakpoint with the breakpoint() function at any position in your code . This is new in Python 3.7, and is equivalent to the older import pdb; pdb. set_trace() command.

How do I break out of pdb?

Whenever you want to leave the pdb console, type the command quit or exit . If you would like to explicitly restart a program at any place within the program, you can do so with the command run .

How do I use pdb debugger in Python?

Starting Python Debugger To start debugging within the program just insert import pdb, pdb. set_trace() commands. Run your script normally and execution will stop where we have introduced a breakpoint. So basically we are hard coding a breakpoint on a line below where we call set_trace().


1 Answers

I found the answer. It's pretty easy actually, there's a command called ignore let's say you want to break at breakpoint in line 9 after 1000 hits:

b 9 

Output: Breakpoint 2 at ...

ignore 1 1000 

Output: Will ignore next 1000 crossings of breakpoint 1.

 c 
like image 140
zenpoy Avatar answered Sep 22 '22 22:09

zenpoy