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

瘦欲@ 提交于 2019-12-03 22:26:41

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...

In my version of Spyder (on Gnome), I cannot type Ctrl+D or Ctrl+Shift+U. So to escape interactive mode, I open a text editor, type Ctrl+Shift+U then, without letting go of Ctrl+Shift, I press Ctrl+Shift+4. This places a character in the text editor that I can highlight and copy. I then paste it into the interactive mode of Spyder and I can get out of interactive mode and back into the debugger.

If you're using Emacs and accessing the pdb interact mode through M-x shell, the best I could find was to call comint-quit-subjob (C-c C-\). This kills the entire debug session and returns you to the shell session rather than killing the entire shell process as comint-send-eof (C-c C-d) would do.

(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 M-x comint-quit-subjob (C-c C-\)
^C
(venv) c:\projects\my-project>

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!