noclew
noclew

Reputation: 542

Stopping ipdb debugging in Jupyter

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".

Upvotes: 1

Views: 1038

Answers (1)

mikitk
mikitk

Reputation: 100

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.

Upvotes: 3

Related Questions