I would like to run and debug some (Sage) code in Windows 10 using pdb, by setting a breakpoint()
in a cell. When I do that, a pdb prompt appears, but it enters into code that is run by (I assume) the interpreter, and not the code in the cell.
I tried using the breakpoint()
function, using pdb explicitly with from IPython.core.debugger import Pdb; Pdb().set_trace()
or with import pdb; pdb.set_trace()
but the same thing always happens.
What can I do to make it work? Here is some example code when I run the command sage --notebook jupyter &
in the Windows Subsystem for Linux (WSL) terminal.. (What happens below also happens if I open a Python3 kernel notebook by running jupyter notebook
in the PowerShell terminal):
breakpoint()
for i in range(10):
print(i)
The output I get is:
--Return--
None
> /tmp/ipykernel_1011/3951840052.py(1)<module>()
----> 1 breakpoint()
2 for i in range(Integer(10)):
3 print(i)
ipdb>
ipdb> n
[... skipped 1 hidden frame]
[... skipped 1 hidden frame]
[... skipped 1 hidden frame]
[... skipped 1 hidden frame]
> /usr/lib/python3/dist-packages/IPython/core/interactiveshell.py(3369)run_ast_nodes()
3367 to_run.append((node, 'single'))
3368
-> 3369 for node,mode in to_run:
3370 if mode == 'exec':
3371 mod = Module([node], [])
ipdb> n
> /usr/lib/python3/dist-packages/IPython/core/interactiveshell.py(3370)run_ast_nodes()
3368
3369 for node,mode in to_run:
-> 3370 if mode == 'exec':
3371 mod = Module([node], [])
3372 elif mode == 'single':
ipdb> n
> /usr/lib/python3/dist-packages/IPython/core/interactiveshell.py(3371)run_ast_nodes()
3369 for node,mode in to_run:
3370 if mode == 'exec':
-> 3371 mod = Module([node], [])
3372 elif mode == 'single':
3373 mod = ast.Interactive([node])
ipdb>
...