python - 为什么 While True 循环不会被 Pycharm 上的“KeyboardInterrupt”中断?
问题描述
我想while True
在下面的代码中中断我的循环,但它不起作用:
try:
while True:
print(1)
except KeyboardInterrupt:
print('interrupted!')
exit()
我在 PyCharm 中运行这段代码。为什么不Ctrl+C触发KeyboardInterrupt
?
解决方案
你试过按Ctrl+C吗,因为这是正确的方法KeyboardInterrupt
正如@Chris 提到的,它不适用于pycharm。尝试为此使用 Ctrl+F2
推荐阅读
- python - 如何检查列表中的双重元素,然后在 Python 2 中删除这两个元素
- http - Flutter:我收到一个错误,即不再出现在小部件树中的小部件的 State 对象
- azure-devops - 如何在 Azure DevOps 上激活“备用凭据”?
- amazon-web-services - 从运行在 VPC 中的 AWS Lambda 访问 ECS 容器
- asp.net-core - 不记名令牌不会大摇大摆地传递
- pandas - Pandas - 用虚拟值替换列中的文本
- python - Plotly:如何在 plotly express 中找到趋势线的系数?
- java - MongoDB Java 驱动程序返回带引号的字符串
- android - 使用 Timber 时在终端中过滤 android adb 日志
- javascript - 为什么窗口对象原型中没有事件对象?