Jupyter notebook stuck in pdb mode

4.1k views Asked by At

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

3

There are 3 answers

2
Manoj Hegde On

Type c and press Enter to continue execution:

enter image description here

enter image description here

1
Tobias Windisch On

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).

2
Mike Müller On

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