简体   繁体   中英

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 ?

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM