我喜欢使用以下方法检查 Python 脚本中的错误:
$ 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
如何退出这个调试器?