In pdb debugger pdb, as you exit interactive mode without interrupting your debugging session

Using python 3.5.1

When I run the script using the python debug module:

[home]# python -m pdb myscript.py 

This will start a debugging session:

  > /somepath/to/myscript.py(1)<module>() -> import os (Pdb) 

If I want to enter an interactive terminal from a debugging session, I can execute the interact command:

 (Pdb) interact *interactive* >>> 

Now I can interact with the code as if I were in a running interactive python mode, with access to any functions or variable in the script area working in the debugger, at the moment of entering the interact mode.

When I issue a command to exit interactive mode (to continue debugging), it kills the entire debugging session:

 >>> exit() The program exited via sys.exit(). Exit status: None ....long nasty stack trace here.... [home]# 

I also tried quit() and it also completes the debugger.

How can you exit interact mode without ending the entire debugging session? Is it possible?

Ideally, I would like to return to debug mode at the point where I stopped to continue my code.

+20
python debugging pdb
source share
5 answers

Sending 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 ... 
+21
source share

If you are using ipdb and are on Windows/Windows10 , you must use Cntrl-Z > Return to exit the interactive shell.

Tested in ipython/python 3.5 and ipdb and pdb

+5
source share

For those who are looking for a solution in a jupyter laptop (and just don't want to learn emacs yet). I found one that worked (to me from here ).

In the Linux shell:

 echo ^D | xclip -selection clipboard 

But you enter ^ D not as characters, but as ctrl-v ctrl-d ...

0
source share

In my version of Spyder (on Gnome), I cannot type Ctrl+D or Ctrl+Shift+U To exit the interactive mode, I open a text editor, type Ctrl+Shift+U , then, without releasing Ctrl+Shift , Ctrl+Shift+4 . This places the character in a text editor that I can select and copy. Then I insert it into Spyder interactive mode and can exit interactive mode and return to the debugger.

0
source share

If you use Emacs and access the pdb interaction mode through the Mx shell , the best I could find was to call comint-quit-subjob ( Cc C-\ ). This kills the entire debugging session and returns you to the shell session, rather than killing the entire shell process, as comint-send-eof ( Cc Cd ) comint-send-eof .

 (venv) c:\projects\my-project> python my-entry-point.py 550 import ipdb; ipdb.set_trace(context=10) --> 551 print("First line to start debugging at") ipdb> interact *interactive* In : # call Mx comint-quit-subjob (Cc C-\) ^C (venv) c:\projects\my-project> 
0
source share

All Articles