本文介绍了为什么此python键盘中断不起作用? (在pycharm中)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

在pycharm中调试我的代码时,按Ctrl + C时,我的python try/except循环似乎不会触发键盘中断.我的代码如下:

My python try/except loop does not seem to trigger a keyboard interrupt when Ctrl + C is pressed while debugging my code in pycharm. My code look like this:

try:
    while loop:
        print("busy")

except KeyboardInterrupt:
    exit()

编辑:我精简的代码似乎在工作中出现了一些问题,但未产生相同的错误.完整的代码可以在此处查看.我还重新整理了代码(上面的代码),并产生了相同的错误.

There seems to be some problems with my slimmed down code working and not producing the same error. The full code can be viewed here. I have also re-slimed down the code (The code above) and it has produced the same error.

推荐答案

从屏幕截图中可以看出,您正在IDE中运行此代码.关于IDE的问题是,它们与正常运行并不完全相同,尤其是在处理键盘字符时.按ctrl-c的方式,IDE认为您要复制文本. python程序永远看不到字符.也许在运行时会弹出一个单独的窗口?然后,您可以在ctrl-c之前选择该窗口.

From your screen shot it appears that you are running this code in an IDE. The thing about IDEs is that they are not quite the same as running normally, especially when it comes to handling of keyboard characters. The way you press ctrl-c, your IDE thinks you want to copy text. The python program never sees the character. Pehaps it brings up a separate window when running? Then you would select that window before ctrl-c.

这篇关于为什么此python键盘中断不起作用? (在pycharm中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-07 02:14