Why doesn#39;t this python keyboard interrupt work? (in pycharm)(为什么这个 python 键盘中断不起作用?(在pycharm中))
问题描述
在 pycharm 中调试我的代码时,当按下 Ctrl + C 时,我的 python try/except 循环似乎不会触发键盘中断.我的代码如下所示:
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()
我的精简代码似乎存在一些问题,但没有产生相同的错误.完整代码可以查看这里.我还重新精简了代码(上面的代码),它产生了同样的错误.
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.
推荐答案
从您的屏幕截图看来,您正在 IDE 中运行此代码.IDE 的问题在于它们与正常运行并不完全相同,尤其是在处理键盘字符时.您按 ctrl-c 的方式,您的 IDE 认为您想要复制文本.python 程序永远不会看到这个字符.也许它在运行时会打开一个单独的窗口?然后你会在 ctrl-c 之前选择那个窗口.
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.
这篇关于为什么这个 python 键盘中断不起作用?(在pycharm中)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:为什么这个 python 键盘中断不起作用?(在pycharm中


基础教程推荐
- 使用PyInstaller后在Windows中打开可执行文件时出错 2022-01-01
- Dask.array.套用_沿_轴:由于额外的元素([1]),使用dask.array的每一行作为另一个函数的输入失败 2022-01-01
- 用于分类数据的跳跃记号标签 2022-01-01
- 何时使用 os.name、sys.platform 或 platform.system? 2022-01-01
- 如何让 python 脚本监听来自另一个脚本的输入 2022-01-01
- 线程时出现 msgbox 错误,GUI 块 2022-01-01
- 在 Python 中,如果我在一个“with"中返回.块,文件还会关闭吗? 2022-01-01
- Python kivy 入口点 inflateRest2 无法定位 libpng16-16.dll 2022-01-01
- 如何在海运重新绘制中自定义标题和y标签 2022-01-01
- 筛选NumPy数组 2022-01-01