2016-08-23 168 views
16

我喜欢通过检查在Python脚本错误:如何在验尸调试时退出ipdb?

$ python3 -m pdb my_script.py 

这滴我到一个PDB提示从哪里可以c继续执行,并且当它击中的错误,我可以检查变量,然后q退出脚本执行以返回到我的shell。

我试着用IPython的调试器模块一样,因为它是更加丰富多彩:

$ python3 -m ipdb my_script.py 

但是,我不能退出调试一旦我做了检查错误。使用q quit命令只是不断重新执行脚本和验尸模式之间的切换是:

$ 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 

如何退出这个调试?

+1

不^ C或^ d不行?我偶尔会得到类似的东西,不得不^ C几次退出 – spruceb

+1

@spruceb那也不管用! –

+0

出现最坏的情况,^ Z,那么'杀人%1'应该停止它的 – spruceb

回答

2

这是在IPython中5.1的bug。它已在this pull request中修复,并且不再是IPython 5.2及之后的版本。您现在可以使用q,quit()Ctrl + d退出调试器。

15

当用户@ffeast评论,有an open ipdb issue,和几个解决方法建议。对我来说,这些行之有效:

  • 按CTRL +ž
  • 执行ipdb> import os; os._exit(1)