pycharm无法捕捉KeyboardInterrupt?

# 捕捉KeyboardInterrupt错误
import time
try:
    while True:
        print("你好")
        time.sleep(1)
except KeyboardInterrupt as results:
    print(results)
    print("终止")
finally:
    print("怎么了")
print("好!")

代码如上,

在cmd和pycharm的终端中都可以正常运行。按ctrl +c可以显示"终止",但是用pycharm跑就不行,一按停止或者ctrl +F2,就是直接退出,捕捉不到KeyboardInterrupt,但可以显示Process finished with exit code -1

请问有没同学知道为什么呢?

我的电脑系统是windows7。

单位的windows10装的pycharm可以正常捕捉。

以为是设置问题,重装pycharm和恢复pycharm默认设置,好像都没用。

在pycharm中测试没有任何意义,因为你最终的运行环境并不是这样的
这种捕捉鼠标键盘的操作高度依赖于系统,你必须在对应的环境下进行测试