简体   繁体   English

阻止PyCharm在KeyboardInterrupt和其他场合显示内置模块

[英]Prevent PyCharm from showing builtin modules on KeyboardInterrupt and other occasions

In PyCharm when an Error occurs the IDE opens the module that produced the Error (this is especially annoying when the Error was produced by pressing Ctrl+C ). 在PyCharm中,当出现错误时,IDE会打开产生错误的模块(当按Ctrl+C生成错误时,这尤其令人讨厌)。

It also opens the module in which the program currently "is" when pausing in Debug mode. 在打开调试模式时,它还会打开程序当前“正在”的模块。 Is there a way to disable this behavior for built-in modules? 有没有办法禁用内置模块的这种行为? (Preferably with a way of showing the exception anyway in case you want to see the source of the built-in module) (最好以一种方式显示异常,以防您想要查看内置模块的来源)

As I posted later here you can Edit PyDev's source to prevent parts of this from happening: 正如我稍后在这里发布的那样您可以编辑PyDev的源代码以防止部分内容发生:

First, you have to find the source for the PyDev interactive interpreter (which is used by PyCharm). 首先,您必须找到PyDev交互式解释器的源(PyCharm使用它)。 On my Windows machine it is located in C:\\Program Files (x86)\\PyCharm\\helpers\\PyDev (path my vary of course). 在我的Windows机器上,它位于C:\\Program Files (x86)\\PyCharm\\helpers\\PyDev (路径我的变化当然)。

The problem can be fixed by editing the file _pydev_imps/_pydev_execfile.py (in the PyDev source directory). 可以通过编辑文件_pydev_imps/_pydev_execfile.py (在PyDev源目录中)来解决此问题。 Line 18 reads 第18行读

exec(compile(contents+"\n", file, 'exec'), glob, loc)

wrap it in a try ... except block with the following code as exception handler 将它包装在try ... except块中,使用以下代码作为异常处理程序

import traceback; traceback.print_exc()

I accept the bounty as it pointed to the right direction: 我接受赏金,因为它指出了正确的方向:

applying the same trick to the file pydevd.py line 1793 finally solved it for me!! 将相同的技巧应用到文件pydevd.py第1793行终于为我解决了!!

        try:
          launch(file, globals, locals)  # execute the script
        except:
          import traceback; traceback.print_exc()

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

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