简体   繁体   English

如何实现try / except的结果与键盘中断相同?

[英]How to implement a try/except with the same result as a keyboardinterrupt?

I want to exit the program at a specific position (except statement) for debugging. 我想在特定位置(语句除外)退出程序进行调试。 Further, I want to be able to stay in the console and play with the variables and objects (DataFrames) which have been defined so far by the program. 此外,我希望能够留在控制台中并使用程序到目前为止已定义的变量和对象(DataFrame)。 Just as when hitting strg*c, but at a position I can control more precisely. 就像击中strg * c一样,但在某个位置我可以更精确地控制。

sys.exit() will also shut down the console and all objects are "lost? sys.exit()还将关闭控制台,并且所有对象均“丢失?

You can use debugger 您可以使用debugger

try:
   #code
except:
   import pdb;pdb.set_trace()

So you will get a shell to debug. 这样您将获得一个Shell进行调试。

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

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