[英]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.