Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to remove a break point set with ipdb.set_trace()?

I used ipdb.set_trace() somewhere in my Python code. Is it possible to ignore this break point using a IPDB command?

clear tells me that it cleared all break points, but IPDB stops again when it stumbles upon the line with ipdb.set_trace().

disable 1 tells me: No breakpoint numbered 1 ignore 1 says: Breakpoint index '1' is not valid

To clarify: Of course I could simply remove the break point from my source code. But this would require to quit the debugger and to start it again. Often it needs a lot of work to get somewhere and restarting the debugger makes life more difficult. Also if there is a huge loop and you want inspect objects in the loop, the easiest is to place a break point in the loop directly after the object. How could I then skip the loop (and all thousands of calls set_trace()) and step through the code after the loop using next?

like image 250
lumbric Avatar asked Sep 30 '13 16:09

lumbric


People also ask

How do you remove a breakpoint in pdb?

To remove all commands from a breakpoint, type commands and follow it immediately with end ; that is, give no commands. Specifying any command resuming execution (currently continue , step , next , return , jump , skip , and quit ) terminates the command list as if that command was immediately followed by end .

What is the use of function pdb Set_trace ()?

Importing the pdb module and running the pdb. set_trace() function lets you begin your program as usual and run the debugger through its execution.

Which command is used to delete the breakpoint?

Deleting breakpoints With the clear command you can delete breakpoints according to where they are in your program. With the delete command you can delete individual breakpoints, watchpoints, or catchpoints by specifying their breakpoint numbers. It is not necessary to delete a breakpoint to proceed past it.

How do you set a breakpoint in pdb?

Optionally, you can also tell pdb to break only when a certain condition is true. Use the command b (break) to set a breakpoint. You can specify a line number or a function name where execution is stopped. If filename: is not specified before the line number lineno , then the current source file is used.


2 Answers

Well, you CAN take advantage of the fact that anything in Python is an object. While in the debugger, you can do something like this:

def f(): pass ipdb.set_trace = f 

set_trace will still be called, but it won't do anything. Of course, it's somewhat permanent, but you can just do

reload ipdb 

and you'll get the original behaviour back.

(why would you do this? when you accidentally put a breakpoint in an often-called function that is usually called under a try/except. Once you realize you're stopping 1000 times in this function, you try to ctrl-c, but that gets caught by the try/except and you're back in ipdb again. So, if you're in low-level code, make sure your set_traces have some context:

if myvar in ['some', 'sentinel', 'values']:     ipdb.set_trace() 

etc.

like image 51
Corley Brigman Avatar answered Sep 19 '22 13:09

Corley Brigman


After learning from Corley

ipdb.set_trace = lambda: None 

Works for me.

like image 43
GLaDOS Avatar answered Sep 18 '22 13:09

GLaDOS