Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Jupyter notebook stuck in pdb mode

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

like image 844
wkzhu Avatar asked Jan 09 '17 16:01

wkzhu


People also ask

How do you stop a pdb in a Jupyter notebook?

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

How do I exit interactive mode in pdb?

If you enter pdb interactive mode there is no way to return to ipdb or ipython. The proper way to exit is by using ctrl-d .

Why is my Jupyter notebook stuck?

Try disabling any browser extensions and/or any Jupyter extensions you have installed. Some internet security software can interfere with Jupyter. If you have security software, try turning it off temporarily, and look in the settings for a more long-term solution.

How do I reset my Jupyter notebook output?

You can use IPython. display. clear_output to clear the output of a cell.


1 Answers

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

like image 198
Tobias Windisch Avatar answered Sep 18 '22 18:09

Tobias Windisch