我正在开发一个 PyKDE4/PyQt4 应用程序Autokey,我注意到当我向程序发送 CTRL+C 时,直到我与应用程序交互时才会处理键盘中断,即通过 ie。单击菜单项或更改复选框。
lfaraone@stone:~$ /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/autokey 中有以下内容:
#!/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:
- 当我发出它时,而不是当我下一次在 GUI 中采取行动时
- 通过最初的 try/except 子句?
使用 Python 2.6 运行 Ubuntu 9.04。