简体   繁体   English

如果python在异常时死掉,怎么能让python进入交互模式?

[英]How can I make python go into interactive mode only if it dies on exception?

Is there a way to invoke a python program such that it will run normally if it does not die, but if it has an uncaught exception, to behave as though it were run with -i ? 有没有办法调用python程序,如果它没有死,它将正常运行,但如果它有一个未捕获的异常,表现得好像它是用-i运行的?

The reason is that I am running my python program from an external script, and it does not encounter the exceptional condition until several runs in. So I want to just lazily go into interactive mode so I can then load up the debug module and look at the postmortem to see the stack variables, but not to have it fall into the interactive prompt for all the earlier runs of the program which do succeed. 原因是我从外部脚本运行我的python程序,并且在几次运行之前它没有遇到异常情况。所以我想懒得进入交互模式,这样我就可以加载调试模块并查看事后查看堆栈变量,但不要让它落入交互式提示中,以便成功完成程序的所有早期运行。

将函数填入sys.excepthook ,使用code创建控制台。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在 python 交互模式下如何导入手工模块 - In python interactive mode how can i import a handmade module 在 Python 中,如何使用 Arcade 中的图像制作交互式按钮? - In Python, how can i make an interactive button using images in arcade? 如何在交互模式下打破异常以调试Python脚本? - How to break in interactive mode on an exception to debug a Python script? 如何监视 Python 进程并在它死掉时重新启动? - How can I monitor a Python process and relaunch if it dies? 将 Python 作为子进程调用时,是否可以强制它以交互模式运行? - When calling Python as a subprocess, can I force it to run in interactive mode? 我可以在交互模式下访问python中的sys.argv吗? - Can I access sys.argv in python in interactive mode? 我可以在python交互模式下有多个matplotlib绘图窗口吗? - Can I have multiple matplotlib plot windows in python interactive mode? 在非交互式 SSH 模式下运行命令时,如何使用相对路径 Python? - How can I use a relative Python path when running a command in non-interactive SSH mode? 在python交互模式下,如何查看类内部变量的值? - How can I see the value of a variable that is inside a class during python interactive mode? 如何使这个 Python 程序具有交互性? - How do I make this Python program interactive?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM