我正在研究一个PyKDE4/PyQt4应用程序Autokey,我注意到当我发送一个CTRL + C的程序时,键盘中断不会被处理,直到我与应用程序交互,即按ie。点击菜单项或更改复选框。在KDE Python应用程序中处理KeyboardInterrupt?
[email protected]:~$ /usr/bin/autokey
^C^C^C
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/autokey/ui/popupmenu.py", line 113, in on_triggered
def on_triggered(self):
KeyboardInterrupt
^C^C^C
Traceback (most recent call last):
File "/usr/lib/python2.6/dist-packages/autokey/ui/configwindow.py", line 423, in mousePressEvent
def mousePressEvent(self, event):
KeyboardInterrupt
尽管这是具有下列在/ usr/bin中/自动密钥:
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
from autokey.autokey import Application
a = Application()
try:
a.main()
except KeyboardInterrupt:
a.shutdown()
sys.exit(0)
为什么没有一个KeyboardInterrupt抓到:
- 当我发出了它,而不是当我接下来通过最初的try/except子句在GUI
- 中采取行动?
使用Python 2.6运行Ubuntu 9.04。
如果sig尽快被捕获,那么它显示KeyboardInterrupt没有被提出的原因是你在Qt中的基于C的事件循环中,并且Python解释器没有机会注册^ C直到事件循环的下一次。 – 2009-08-31 15:36:57
我更新了我的答案。 – 2009-08-31 21:06:42