turning ctrl-break (or ctrl-c) into KeyboardInterrupt

Dear list,

At the moment, when I press Ctrl-C in the command window (or terminal) from whence I invoke a wxPython application, everything terminates summarily.

Is it possible to turn this Ctrl-C into something like a KeyboardInterrupt? What I actually want to do is have some kind of panic button so that I can interrupt the wxPython program at any time and have it generate an exception at the current instruction. For example, if the program is somehow caught in some long processing task and I'm not sure where exactly, I would like to be able to terminate/interrupt the program and know what exactly it was busy with.

It would be ideal if this could work on *ix and Windows. I've tried installing a SIGINT handler on Windows, but this doesn't seem to work.

Thanks,
Charl

···

--
charl p. botha http://cpbotha.net/ http://visualisation.tudelft.nl/

Charl P. Botha wrote:

Dear list,

At the moment, when I press Ctrl-C in the command window (or terminal) from whence I invoke a wxPython application, everything terminates summarily.

Is it possible to turn this Ctrl-C into something like a KeyboardInterrupt? What I actually want to do is have some kind of panic button so that I can interrupt the wxPython program at any time and have it generate an exception at the current instruction. For example, if the program is somehow caught in some long processing task and I'm not sure where exactly, I would like to be able to terminate/interrupt the program and know what exactly it was busy with.

It would be ideal if this could work on *ix and Windows. I've tried installing a SIGINT handler on Windows, but this doesn't seem to work.

On wxGTK I think that the X toolkit is installing a default signal handler for SIGINT so it causes an exit when Ctrl-C is pressed in the console that starts the app. Try it with other X apps I think you'll see that it behaves the same way. So wxPython's wx.PyApp.__init__ is clearing the default Python SIGINT handler to allow that behaviour to happen. If wxPython doesn't clear the SIGINT then Python still tries to raise a KeyboardInterrupt but for some reason I still don't understand it doesn't actually get raised until app.MainLoop exits which isn't very helpful (and it used to segfault at exit too but I think that has been fixed.)

I don't recall off the top of my head how the other platforms behaved with SIGINT...

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!