Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jupyter, Python, %Debug: Setting breakpoint in module doesn't work

I am using Jupyter Notebook.

Considering the following code:

cell1

import pdbtest  

cell2

%debug -b pdbtest.py:3
pdbtest.test(4,6)

end of cell2

pdbtest.py is a module located in the same folder as the notebook, containing:

def test(a,b):
    print("hello")
    a=a*2
    print("goodbye")
    b=b*2

Normally the %debug magic should set a breakpoint on the third line of the module. When run , this code returns:

Breakpoint 1 at /home/depot/notebooks/pdbtest.py:3
NOTE: Enter 'c' at the ipdb>  prompt to continue execution.
hello
goodbye

It seems the console has well understood the file and the location where the breakpoint should be, and give the return of the function. However it doesn't stop on the breakpoint!

Anyone has experienced the same?

like image 666
Radar Avatar asked Jan 10 '17 09:01

Radar


1 Answers

In your example, the %debug magic command is only valid for the Python code that follows it in the same line, i.e., nothing.

If you want it to be valid for the whole cell, then you should use %%debug:

%%debug -b pdbtest.py:3
pdbtest.test(4,6)
like image 104
André Panisson Avatar answered Sep 20 '22 21:09

André Panisson