I am trying to understand debugging in jupyter notebooks. As per my understanding applying breakpoint()
is the way to go about it but I am landing into a few issues that I describe below. I have a file named test_debugger.py
in ./
that I am using as a prop in my little understanding endeavor.
#./test_debugger.py
def fun1(a):
print(a)
breakpoint()
if a > 3:
print(a+1)
breakpoint()
print(a+2)
breakpoint()
return None
Setup:
from test_debugger import *
Issues:
- breakpoint() enters into debugging the interactive shell:
print(5)
breakpoint()
fun1(4)
breakpoint()
Running the above code gives me
5
--Return--
None
> <ipython-input-2-4276bdd18b42>(2)<module>()
1 print(5)
----> 2 breakpoint()
3 fun1(4)
4 breakpoint()
ipdb>
I press n
and I want to jump to the next line in the cell but it gets into debugging the interactive shell I guess. Upon pressing n
I get:
ipdb> n
[... skipped 1 hidden frame]
[... skipped 1 hidden frame]
[... skipped 1 hidden frame]
[... skipped 1 hidden frame]
> /home/nitin/miniconda/envs/nyraml386/lib/python3.8/site-packages/IPython/core/interactiveshell.py(3330)run_ast_nodes()
3328 to_run.append((node, 'single'))
3329
-> 3330 for node,mode in to_run:
3331 if mode == 'exec':
3332 mod = Module([node], [])
ipdb>
Question: How do I get the desired functionality of n
(jump to next line in code written by me while remaining in the same function score) and s
(jump to the next line in code written by me while switching the function scope wherever necessary).
- PYTHONBREAKPOINT not available in jupyter notebook
The behavior expected: I have read that in case I want to disable all breakpoint()
then I can set the env variable PYTHONBREAKPOINT
to manage the behavior of breakpoint()
. Specifically, I can set PYTHONBREAKPOINT=0
to disable breakpoint()
The behavior seen: PYTHONBREAKPOINT
is not a variable available at all in jupyter notebook. Even if I set it equal to 0 that does not alter the disable breakpoint()
. It is as if nothing happened
Question: How to manage breakpoint()
when operating in jupyter notebooks. What is the way to bring in PYTHONBREAKPOINT
into the notebook