title: Handling KeyboardInterrupt in a KDE Python application?
body: <p>I'm working on a PyKDE4/PyQt4 application, <a href="http://autokey.googlecode.com/" rel="nofollow noreferrer">Autokey</a>, and I noticed that when I send the program a CTRL+C, the keyboard interrupt is not processed until I interact with the application, by ie. clicking on a menu item or changing a checkbox. </p>
  
  <pre><code>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
  </code></pre>
  
  <p>This is despite having the following in  /usr/bin/autokey:</p>
  
  <pre><code>#!/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)
  </code></pre>
  
  <p>Why isn't the KeyboardInterrupt caught:</p>
  
  <ul>
  <li>when I issue it, rather than when I next take an action in the GUI</li>
  <li>by the initial try/except clause?</li>
  </ul>
  
  <p>Running Ubuntu 9.04 with Python 2.6.</p>