Jupyter notebook stuck in pdb mode
Asked Answered
L

3

14

I'm using Jupyter (IPython) notebook, where pdb / ipdb runs fine, except for one problem: If I accidentally run the same cell that my pdb is in while in pdb mode, the output disappears, the entire notebook gets stuck and I can't run any more commands. I also tried interrupting or restarting the kernel; doesn't work. My only option is to shut down the notebook, and restart it.

Does anyone else experience this problem / know of a solution? Very annoying for me to have to restart the notebook every time I make this mistake.

Here are screenshots of the problem. Below I'm in pdb mode as expected:

enter image description here

If I then (accidentally) run the same cell my pdb is in, the notebook gets stuck trying to run that cell, and won't run anything else (like the cell below).

enter image description here

Luge answered 9/1, 2017 at 16:10 Comment(4)
'Kernel -> Interrupt' (or Restart) to exit out of the pdb loop. You should q(uit) pdb if you want your kernel to continue running before running another cell.Plasticity
Restart works but Interrupt does not unfortunately (at least for me). Yes, quitting pdb is obviously what I want to do but the question is for if I run the pdb cell accidentally (which happens surprisingly often...), in which case the pdb input bar disappears.Luge
See Problems with shell commands (magic) expecting output · Issue #10499 · ipython/ipython for a bug report on this.Geophysics
See this Github issue: github.com/ipython/ipython/issues/10516Szczecin
F
1

In newer versions of Jupyter (mine is 6.1.4), pressing the "Interrupt kernel" button solves the problem (and you keep all your variables and your python session):

enter image description here

Pressing the button after you re-run the cell yielding the break point, you again get the pdb console printed to the output of the cell where you then can interact with pdb again. It seems that the "Interrupt kernel" works like a Keyboard interrupt, forcing the output cell to refresh.

Pressing i twice after the re-run has the same effect (see also this post).

Faviolafavonian answered 25/2, 2021 at 18:21 Comment(1)
This does not appear to work if you have deleted the cell that produced the PDB console.Sankey
D
-1

Looks like you need to restart. Click on the menu "Kernel", select "Restart" and click on the button "Restart". Now, re-execute your cell.

Deceptive answered 9/1, 2017 at 16:30 Comment(2)
Looks like it works but I lose my variables - guess there's no better way?Luge
Not that I know of. A simple interrupt does not work.Celery
B
-1

Type c and press Enter to continue execution:

enter image description here

enter image description here

Bergson answered 25/2, 2021 at 18:13 Comment(2)
I think his problem is that he cannot enter something into the console opened by pdb as he rerun the cell.Faviolafavonian
@Wondercricket The answer doesn’t really contain code, and screenshots seem entirely appropriate in this case (that said, I suspect Tobias is right).Northwards

© 2022 - 2024 — McMap. All rights reserved.