gotcha / ipdb

Integration of IPython pdb
BSD 3-Clause "New" or "Revised" License
1.85k stars 146 forks source link

Why Python's breakpoint and ipdb behave this way? #222

Open Icarwiz opened 3 years ago

Icarwiz commented 3 years ago

I apologize in advance if this is not really an issue...

I'm used to debugging in Python with PyCharm.

Now I'm trying to learn using ipdb with Jupyter(Lab to be precise).

But the two following behaviours are really puzzling me !

First one

breakpoint()
for i in range(3):
    print(i)

Then in the debugger :

--Return--
None
> <ipython-input-10-45409e3598c5>(1)<module>()
----> 1 breakpoint()
      2 for i in range(3):
      3     print(i)

ipdb>  n

    [... skipped 1 hidden frame]

    [... skipped 1 hidden frame]

    [... skipped 1 hidden frame]

    [... skipped 1 hidden frame]

> c:\users\icar\anaconda3\envs\jlab3\lib\site-packages\ipython\core\interactiveshell.py(3349)run_ast_nodes()
   3347                     to_run.append((node, 'single'))
   3348 
-> 3349                 for node,mode in to_run:
   3350                     if mode == 'exec':
   3351                         mod = Module([node], [])

Why ipdb next makes ipdb stopping in run_ast_nodes ?

Isn't it supposed to be an equivalent to step over ?

Second one

for i in range(3):
    breakpoint()
    print(i)

Then in the debugger :

None
> <ipython-input-9-2b8431878fa0>(3)<module>()
      1 for i in range(3):
      2     breakpoint()
----> 3     print(i)

ipdb>  c

0
None
> <ipython-input-9-2b8431878fa0>(2)<module>()
      1 for i in range(3):
----> 2     breakpoint()
      3     print(i)

ipdb>  c

1
None
> <ipython-input-9-2b8431878fa0>(3)<module>()
      1 for i in range(3):
      2     breakpoint()
----> 3     print(i)

What can explain ipdb continue alternates stopping on line 3, then 2, then 3 again ?

I guess I'm missing something, but I can't get it, it's just elementary stuff...

reject-cookies commented 1 year ago

This is happening to me too. But only when ipdb set trace is outside of any function. Very strange.