gpt4 book ai didi

python - 如何在事后调试时退出 ipdb?

转载 作者:IT老高 更新时间:2023-10-28 20:21:27 31 4
gpt4 key购买 nike

我喜欢使用以下方法检查 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

如何退出这个调试器?

最佳答案

正如用户@feast 评论的那样,有an open ipdb issue ,并提出了一些解决方法。对我来说,这些效果很好:

  • ctrl+zkill %1(或任何作业编号)
  • 执行 ipdb> 导入操作系统; os._exit(1)

关于python - 如何在事后调试时退出 ipdb?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39090752/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com