21

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.

1
  • 2
    I filed a bug on the Python issue tracker asking to add a command to exit the PDB InteractiveConsole: bugs.python.org/issue41096 Commented Jun 24, 2020 at 18:02

3 Answers 3

8

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.

Sign up to request clarification or add additional context in comments.

2 Comments

on my macOS, echo -e '\x04' | pbcopy. Thanks, though, this worked great.
@zmccord I just tried this on macOS and it works with or without -e for me. Not sure what the difference between your system configuration and mine is.
6

A platform-agnostic method to solve this is to use pandas (doesn't require the terminal or Emac) :

  • Run this in the interactive console itself:
    from pandas.io.clipboard import copy; copy("\x04")
    
  • And then do ctrl+v to paste the 'end of transmittion charecter' and hit Enter.

Comments

1

The only way I have been success is to copy/paste the Crtl-D character from another source. I use Emacs, so this is fairly easy, but any text editor that allows you to insert a Crtl-D into the document should work. Once inserted, use the standard copy/paste into the pdb interact field and hit or . This should get you out.

For Emacs, the long way is as follows, for demonstration purposes:

M-x insert char <RET> END OF TRANSMISSION <RET>

At this point you should see ^D in the buffer. At this point select the character and M-w or kill-ring-save to put it on the clipboard.

Then, change to the browser and make the interactive field active, and paste the character back. You will not see anything. Then hit . This should/might get you out.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.