wxPython eats Ctrl+C?

Hello,

I am writing a program that intercepts some signals, such as Ctrl+C, and quits cleanly. I have a base class that sets-up signal handlers and it works great. I've recently had to integrate wxPython in parts of my application and I've inherited from my base class (we'll call it MyBaseClass) and wx.App. The interface works great, but when I'm in the terminal were the program was run from, and I send SIGINT (Ctrl+C) nothing happens. Does anyone know why wxPython eats my Ctrl+C in the terminal? This code works without the wxPython. I would imagine that in the GUI it eats it because it intercepts it as the "copy" shortcut, but not in the terminal. How can I get it to work?

Thank you,
Gabriel

I've not experienced the behavior you observed. In Windows, Linux,
and OS X, hitting ctrl+c in the terminal kills Python and wxPython.
You may want to check your signal handlers, and/or create a new
handler for sigint that raises a SystemExit exception, making sure to
set secondary threads as daemonic (if they are being used and if you
haven't done so already).

- Josiah

···

On Thu, Aug 21, 2008 at 5:08 AM, Gabriel Rossetti <gabriel.rossetti@arimaz.com> wrote:

Hello,

I am writing a program that intercepts some signals, such as Ctrl+C, and
quits cleanly. I have a base class that sets-up signal handlers and it works
great. I've recently had to integrate wxPython in parts of my application
and I've inherited from my base class (we'll call it MyBaseClass) and
wx.App. The interface works great, but when I'm in the terminal were the
program was run from, and I send SIGINT (Ctrl+C) nothing happens. Does
anyone know why wxPython eats my Ctrl+C in the terminal? This code works
without the wxPython. I would imagine that in the GUI it eats it because it
intercepts it as the "copy" shortcut, but not in the terminal. How can I get
it to work?

Thank you,
Gabriel
_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwidgets.org
http://lists.wxwidgets.org/mailman/listinfo/wxpython-users

Are you sure you don’t have a bare except statement somewhere that isn’t swallowing the KeyboardInterrupt? This is one of the least well-thought-out features of Python:

http://effbot.org/zone/stupid-exceptions-keyboardinterrupt.htm

-Nat

···

On Thu, Aug 21, 2008 at 5:08 AM, Gabriel Rossetti gabriel.rossetti@arimaz.com wrote:

I am writing a program that intercepts some signals, such as Ctrl+C, and quits cleanly. I have a base class that sets-up signal handlers and it works great. I’ve recently had to integrate wxPython in parts of my application and I’ve inherited from my base class (we’ll call it MyBaseClass) and wx.App. The interface works great, but when I’m in the terminal were the program was run from, and I send SIGINT (Ctrl+C) nothing happens. Does anyone know why wxPython eats my Ctrl+C in the terminal? This code works without the wxPython. I would imagine that in the GUI it eats it because it intercepts it as the “copy” shortcut, but not in the terminal. How can I get it to work?

Nathaniel Echols wrote:

···

On Thu, Aug 21, 2008 at 5:08 AM, Gabriel Rossetti > <gabriel.rossetti@arimaz.com <mailto:gabriel.rossetti@arimaz.com>> wrote:

    I am writing a program that intercepts some signals, such as
    Ctrl+C, and quits cleanly. I have a base class that sets-up signal
    handlers and it works great. I've recently had to integrate
    wxPython in parts of my application and I've inherited from my
    base class (we'll call it MyBaseClass) and wx.App. The interface
    works great, but when I'm in the terminal were the program was run
    from, and I send SIGINT (Ctrl+C) nothing happens. Does anyone know
    why wxPython eats my Ctrl+C in the terminal? This code works
    without the wxPython. I would imagine that in the GUI it eats it
    because it intercepts it as the "copy" shortcut, but not in the
    terminal. How can I get it to work?

Are you sure you don't have a bare except statement somewhere that isn't swallowing the KeyboardInterrupt? This is one of the least well-thought-out features of Python:

http://effbot.org/zone/stupid-exceptions-keyboardinterrupt.htm

-Nat

Yes, I checked in my parent classes too, unless the wxPython classes have one that's not the problem, thanks though, I didn't know that :slight_smile:

Gabriel Rossetti wrote:

Hello,

I am writing a program that intercepts some signals, such as Ctrl+C, and quits cleanly. I have a base class that sets-up signal handlers and it works great. I've recently had to integrate wxPython in parts of my application and I've inherited from my base class (we'll call it MyBaseClass) and wx.App. The interface works great, but when I'm in the terminal were the program was run from, and I send SIGINT (Ctrl+C) nothing happens. Does anyone know why wxPython eats my Ctrl+C in the terminal? This code works without the wxPython. I would imagine that in the GUI it eats it because it intercepts it as the "copy" shortcut, but not in the terminal. How can I get it to work?

Thank you,
Gabriel

Apparently it's due to the mix of wxPython and another framework that I use (Twisted), I looking into it with their mailing list. Thanks for you help, I'll keep you posted (in case it ever happens to someone here).

Gabriel

Gabriel Rossetti wrote:

Hello,

I am writing a program that intercepts some signals, such as Ctrl+C, and quits cleanly. I have a base class that sets-up signal handlers and it works great. I've recently had to integrate wxPython in parts of my application and I've inherited from my base class (we'll call it MyBaseClass) and wx.App. The interface works great, but when I'm in the terminal were the program was run from, and I send SIGINT (Ctrl+C) nothing happens. Does anyone know why wxPython eats my Ctrl+C in the terminal? This code works without the wxPython. I would imagine that in the GUI it eats it because it intercepts it as the "copy" shortcut, but not in the terminal. How can I get it to work?

This is something that I struggled with several years ago, and was never able to resolve. The various GUIs and/or platforms all intercept Ctrl-C or SIGINT in one way or another and so Python isn't able to get it and turn it into a KeyboardInterrupt. I tried a bunch of different approaches, but nothing worked consistently, (other than letting them just exit.)

···

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

Robin Dunn wrote:

Gabriel Rossetti wrote:

Hello,

I am writing a program that intercepts some signals, such as Ctrl+C, and quits cleanly. I have a base class that sets-up signal handlers and it works great. I've recently had to integrate wxPython in parts of my application and I've inherited from my base class (we'll call it MyBaseClass) and wx.App. The interface works great, but when I'm in the terminal were the program was run from, and I send SIGINT (Ctrl+C) nothing happens. Does anyone know why wxPython eats my Ctrl+C in the terminal? This code works without the wxPython. I would imagine that in the GUI it eats it because it intercepts it as the "copy" shortcut, but not in the terminal. How can I get it to work?

This is something that I struggled with several years ago, and was never able to resolve. The various GUIs and/or platforms all intercept Ctrl-C or SIGINT in one way or another and so Python isn't able to get it and turn it into a KeyboardInterrupt. I tried a bunch of different approaches, but nothing worked consistently, (other than letting them just exit.)

I just saw that wx.App() has the following parameter :

clearSigInt - Should SIGINT be cleared? This allows the app to terminate upon a Ctrl-C in the console like other GUI apps will.

Which seams to be what I want. I tried setting it to False, and it sort of works, but the App dies only after an event happens, since it is a TaskBarIcon it's not very convenient because I have to do something like open the menu (right click).

I'm making a wild guess here. Try adding a timer, and in the timer call wx.WakeUpIdle().

···

At 12:49 AM 8/25/2008, you wrote:

Robin Dunn wrote:

Gabriel Rossetti wrote:

Hello,

I am writing a program that intercepts some signals, such as Ctrl+C, and quits cleanly. I have a base class that sets-up signal handlers and it works great. I've recently had to integrate wxPython in parts of my application and I've inherited from my base class (we'll call it MyBaseClass) and wx.App. The interface works great, but when I'm in the terminal were the program was run from, and I send SIGINT (Ctrl+C) nothing happens. Does anyone know why wxPython eats my Ctrl+C in the terminal? This code works without the wxPython. I would imagine that in the GUI it eats it because it intercepts it as the "copy" shortcut, but not in the terminal. How can I get it to work?

This is something that I struggled with several years ago, and was never able to resolve. The various GUIs and/or platforms all intercept Ctrl-C or SIGINT in one way or another and so Python isn't able to get it and turn it into a KeyboardInterrupt. I tried a bunch of different approaches, but nothing worked consistently, (other than letting them just exit.)

I just saw that wx.App() has the following parameter :

clearSigInt - Should SIGINT be cleared? This allows the app to terminate upon a Ctrl-C in the console like other GUI apps will.

Which seams to be what I want. I tried setting it to False, and it sort of works, but the App dies only after an event happens, since it is a TaskBarIcon it's not very convenient because I have to do something like open the menu (right click).

Gabriel Rossetti wrote:

Robin Dunn wrote:

Gabriel Rossetti wrote:

Hello,

I am writing a program that intercepts some signals, such as Ctrl+C, and quits cleanly. I have a base class that sets-up signal handlers and it works great. I've recently had to integrate wxPython in parts of my application and I've inherited from my base class (we'll call it MyBaseClass) and wx.App. The interface works great, but when I'm in the terminal were the program was run from, and I send SIGINT (Ctrl+C) nothing happens. Does anyone know why wxPython eats my Ctrl+C in the terminal? This code works without the wxPython. I would imagine that in the GUI it eats it because it intercepts it as the "copy" shortcut, but not in the terminal. How can I get it to work?

This is something that I struggled with several years ago, and was never able to resolve. The various GUIs and/or platforms all intercept Ctrl-C or SIGINT in one way or another and so Python isn't able to get it and turn it into a KeyboardInterrupt. I tried a bunch of different approaches, but nothing worked consistently, (other than letting them just exit.)

I just saw that wx.App() has the following parameter :

clearSigInt - Should SIGINT be cleared? This allows the app to terminate upon a Ctrl-C in the console like other GUI apps will.

Yep, that is one of the things I experimented with way back when. Note however that you still wont get a KeyboardInterrupt, IIRC all it's doing is attempting to undo what python did to capture SIGINT. There could still be interference from the native GUI library.

Which seams to be what I want. I tried setting it to False, and it sort of works, but the App dies only after an event happens, since it is a TaskBarIcon it's not very convenient because I have to do something like open the menu (right click).

Ctrl-C exits cleanly for me with the taskbar sample I posted in the other thread.

···

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