1

I am using Jupiter and trying to learn how to debug. However, I cannot complete exit from the debugging mode.

for i in np.arange(1,10, 0.01):
    a = someFunc(i)
    # I want to check the value of "a" in each iteration
    # here!
    from IPython.core.debugger import Tracer; Tracer()() #this one triggers the debugger

If I run this code and type "q" or "exit" in the debugging ipdb prompt, it just keeps running the code until the next break point, and I cannot stop debugging. How can I stop debugging? I looked into the documentation, but could not find any other command than "q".

1 Answer 1

3

You need to start tracing before you enter the loop. What happens currently is that you create a new debugger instance with every loop step.

You code would look like this:

from IPython.core.debugger import Tracer

for i in np.arange(1,10, 0.01):
    a = someFunc(i)
    Tracer()()

You will get a command line prompt where all standard ipdb functions can be used. By calling Tracer right after you execute someFunc(i) you will get a new prompt with every iteration. To continue execution until the next iteration use c command. To set breakpoints use b <line number>. q will stop execution all together.

Sign up to request clarification or add additional context in comments.

5 Comments

Thanks miktik. Then, if I want to check the value of 'a' inside of the loop as above, how can I set the breakpoint inside of the for-loop?
Tracer()() acts as a breakpoint, you can put it right before or after the line you want to check. I've updated my answer, hope it helps (please accept the answer if it does).
Thanks for the update. However, if I run the code above, I still cannot exit from the loop by typing "q". For example, if I type "q" in one iteration, I just get to the next iteration, meaning that I have to press "q" 1000 times to exit the loop. Is there anyway to get out from the loop when the break point is inserted in the loop?
Interesting. For me, if Tracer is imported outside of the loop and initialized inside the loop, q quits the debugger and breaks the loop execution
hmmmmm... this is really annoying :(

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.