Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exit pdb Interactive Mode from Jupyter Notebook

Within pdb, I'm using the interact command to enter interactive mode (documentation).

This gives me an InteractiveConsole within pdb (which I need in order to do list comprehension).

From within a Jupyter Notebook, how do I leave interactive mode without exiting the debugger entirely?

This question is the exact same question but the solutions only work from the terminal.

  • ctrl+d from within Jupyter just adds a bookmark.
  • And quit() returns NameError: name 'quit' is not defined

I can do import sys; sys.exit(), but that exits the debugger entirely, meaning I have to start from scratch.

like image 735
ganesha123 Avatar asked Nov 28 '17 00:11

ganesha123


People also ask

How do I exit pdb interact?

On a related note, if you want to exit the debugger entirely you just press q then enter.

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 you exit debug mode in Jupyter notebook?

You can write exit() to quit debug mode. Show activity on this post. you can use "ctrl+d" to delete the cell.. I just successfully used exit() in my Jupyter (formerly iPython) notebook (on a Mac) to get out of a debug session.

How do I stop Python debugging?

Pausing or Stopping the Debugger At this point you can click the Start button to continue running the script, click the Step button to execute the highlighted line of code, or execute additional Python commands. To stop debugging the script, click the Stop button or press the Esc key.


1 Answers

Here is a solution similar to triccare's which doesn't require Emacs.

Run this command on Linux:

echo '\x04' | xclip -selection clipboard

or this command on macOS:

echo '\x04' | pbcopy

and then paste into PDB interactive prompt in Jupyter and press enter.

How this works: This puts the ASCII character 0x04, "END OF TRANSMISSION", onto your clipboard. This character is a "control character" that signals that there is no more input, which causes the PDB interactive session to end.

like image 74
Kerrick Staley Avatar answered Sep 18 '22 14:09

Kerrick Staley