python键盘中断_为什么此python键盘中断不起作用? (在pycharm中)

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()

EDIT: 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.

解决方案

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.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值