[PyKDE] Re: handling keyboard interrupts nicely?

Burley, Brent Brent.Burley at disney.com
Tue Jan 28 19:49:01 GMT 2003

Martin Blais wrote:
> i have been looking for a FAQ about this, and everywhere else, and i would 
> have thought that would be the first question most people would be asking 
> after trying PyQt:  how do you handle KeyboardInterrupt's from a PyQt app?

Unfortunately, PyQt catches all exceptions and just prints them out. 
I don't believe there's a way to change that behavior.

You can, however, override python's ctrl-c handler using the signal
module.  Note: the handler won't be called until the python
interpreter gets control again.  If what you're trying to do is just
kill the app quickly, then just restoring the default handler will

  import signal; signal.signal(signal.SIGINT, signal.SIG_DFL)

As an alternative, you can try ctrl-\.  On most unix systems, this
sends a sigquit which should kill the app immediately in all cases,
though you'll have to put up with core dumps.  I don't know about

	Brent Burley

More information about the PyQt mailing list