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.
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 .
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.
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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With