为什么 While True 循环不会被 Pycharm 上的“KeyboardInterrupt”中断?
Why While True loop does not interrupt by `KeyboardInterrupt` on Pycharm?
我想在下面的代码中中断我的 while True
循环,但它不起作用:
try:
while True:
print(1)
except KeyboardInterrupt:
print('interrupted!')
exit()
我是运行这个代码在PyCharm。为什么 Ctrl+C 没有触发 KeyboardInterrupt
?
您是否尝试过按 Ctrl+C,因为这是导致 KeyboardInterrupt
的正确方法
正如@Chris 提到的,它不适用于 pycharm。为此尝试使用 Ctrl+F2
在PyCharm中Ctrl+C is bound to "copy". Try Ctrl+F2代替。
我想在下面的代码中中断我的 while True
循环,但它不起作用:
try:
while True:
print(1)
except KeyboardInterrupt:
print('interrupted!')
exit()
我是运行这个代码在PyCharm。为什么 Ctrl+C 没有触发 KeyboardInterrupt
?
您是否尝试过按 Ctrl+C,因为这是导致 KeyboardInterrupt
正如@Chris 提到的,它不适用于 pycharm。为此尝试使用 Ctrl+F2
在PyCharm中Ctrl+C is bound to "copy". Try Ctrl+F2代替。