如何在事后调试中退出ipdb?

Ash*_*ppa 26 python ipython pdb ipdb

我喜欢使用以下方法检查Python脚本中的错误:

$ python3 -m pdb my_script.py
Run Code Online (Sandbox Code Playgroud)

这让我进入了一个pdb提示符,从那里我可以c继续执行,当它遇到错误时,我可以检查变量然后q退出脚本执行以返回到我的shell.

我尝试使用iPython调试器模块,因为它更加丰富多彩:

$ python3 -m ipdb my_script.py
Run Code Online (Sandbox Code Playgroud)

但是,一旦检查完错误,我就无法退出调试器.使用qquit命令只是在重新执行脚本和事后模式之间保持切换:

$ python3 -m ipdb my_script.py
ipdb> c
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
ipdb> Inspect some variables at this point
ipdb> q
Post mortem debugger finished. The my_script.py will be restarted
ipdb> q
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
ipdb> q
Post mortem debugger finished. The my_script.py will be restarted
ipdb> q
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
ipdb> q
Post mortem debugger finished. The my_script.py will be restarted
ipdb> q
Uncaught exception. Entering post mortem debugging
Running 'cont' or 'step' will restart the program
Run Code Online (Sandbox Code Playgroud)

如何退出此调试器?

tut*_*uju 31

正如用户@ffeast评论的那样,有一个开放的ipdb问题,并提出了一些解决方法.对我来说这些效果很好:

  • ctrl+z
  • 执行 kill %1

  • ctrl + z并不会真正退出进程,只是将其发送到后台。例如,您可以使用命令“ fg 1”重新进入调试器,您将看到调试器仍然存在。第二个`import os; os._exit(1)在我的情况下有效。 (2认同)

joe*_*lom 6

这是IPython 5.1中的一个错误.它在此拉取请求中得到修复,不再是IPython 5.2及其后的问题.您现在可以使用q,, quit()Ctrl+ d退出调试器.