简体   繁体   English

为什么虽然True循环不会被Pycharm上的`KeyboardInterrupt`中断?

[英]Why While True loop does not interrupt by `KeyboardInterrupt` on Pycharm?

I want to interrupt my while True loop in below code but it does not work: 我想在下面的代码中打断我的while True循环,但它不起作用:

try:  
    while True:  
        print(1)    
except KeyboardInterrupt:  
    print('interrupted!')  
    exit()

I am running this code in PyCharm. 我在PyCharm中运行此代码。 Why isn't Ctrl + C triggering KeyboardInterrupt ? 为什么Ctrl + C不触发KeyboardInterrupt

Have you tried pressing Ctrl+C, because that's the correct way of causing KeyboardInterrupt 您是否尝试过按Ctrl + C,因为这是导致KeyboardInterrupt的正确方法

As @Chris mentioned it won't work for pycharm. 正如@Chris所说,它不适用于pycharm。 Try using Ctrl+F2 for that 尝试为此使用Ctrl + F2

In PyCharm Ctrl + C is bound to "copy" . 在PyCharm中, Ctrl + C绑定到“ copy” Try Ctrl + F2 instead. 请尝试按Ctrl + F2

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

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