Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Using python 3.5.1

When I run a script using the python debugger module:

  [home]# python -m pdb myscript.py 

This starts a debug session:

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

If I want to enter an interactive terminal from within the debug session I can issue the interact command:

(Pdb) interact *interactive* >>> 

Now I can interact with th code as if I was in a running python interactive mode, with access to any functions or variable in scope of the script running in the debugger at the time I entered interact mode.

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

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

I've also tried quit() and it also terminates the debugger.

How can you exit out of interact mode without terminating the entire debug session? Is this even possible?

Ideally, I'd like to return to into debug mode at the point where I left off so I could continue stepping through my code.

like image 888
Ray Avatar asked Apr 29 '16 18:04

Ray


People also ask

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 .

How do I exit pdb debugger?

To start execution, you use the continue or c command. If the program executes successfully, you will be taken back to the (Pdb) prompt where you can restart the execution again. At this point, you can use quit / q or Ctrl+D to exit the debugger.

How do you clear a Python debugger?

You can clear the Python interpreter console screen using a system call. System calls to clear the console: For the window system, cls clear the console. For the Linux system, clear command works.


2 Answers

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 ... 
like image 81
Lukas Graf Avatar answered Sep 23 '22 17:09

Lukas Graf


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

like image 25
alpha_989 Avatar answered Sep 23 '22 17:09

alpha_989