In the Python debugger pdb, how do you exit interactive mode without terminating the debugging session

Sending an EOF by pressing Ctrl + D should work:

$ python -m pdb myscript.py
> .../myscript.py(1)<module>()
-> import os
(Pdb) import code
(Pdb) code.interact()
Python 2.7.11 (default, Dec 27 2015, 01:48:39)
[GCC 4.2.1 Compatible Apple LLVM 6.0 (clang-600.0.57)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
(InteractiveConsole)
>>> <CTRL-D>
(Pdb) c
...

If you are using ipdb, and are on Windows/Windows10, you should use Cntrl-Z>Return to get out of the interactive shell.

Tested in ipython/python 3.5 and ipdb and pdb


For those who look for a solution in jupyter notebook (and just yet do not want to learn emacs). I found one which worked for me (from here).

In linux shell:

echo ^D | xclip -selection clipboard 

But, you do NOT type ^D as characters but as ctrl-v ctrl-d...