Handling SIGTERM Gracefully?

I'm trying to find a way to gracefully handle SIGTERM in my wxPython
app under Linux. I'd like to call Close() on my main frame from
somewhere so that its OnClose method can close a file. Although some
sources seem to indicate that sys.exitfunc or atexit will work when
SIGTERM is received, those handlers don't seem to get called and I
just see "Terminated" on the console. I also tried setting up a
signal handler using signal.signal. This sort of works. When I send
the SIGTERM (with the kill command), nothing happens, but as soon as I
invoke any event in my app (click on any button, for example), then my
handler is called and the app shuts down nicely.

Is there some step or method I'm missing?

Thanks in advance.

Justin

I don't know enough about the way those things work under Unix, but from what I recaller a signal handler behaves more or less like a short lived thread.

If that is the case all you need is to call wx.CallAfter and pass wx.GetApp().Exit as the parameter.

I've attached and example that uses a threaded timer instead of a signal, but it should work for a signal as well.

Hope it works.

Justin Donnelly wrote:

killapp.py (810 Bytes)

···

I'm trying to find a way to gracefully handle SIGTERM in my wxPython
app under Linux. I'd like to call Close() on my main frame from
somewhere so that its OnClose method can close a file. Although some
sources seem to indicate that sys.exitfunc or atexit will work when
SIGTERM is received, those handlers don't seem to get called and I
just see "Terminated" on the console. I also tried setting up a
signal handler using signal.signal. This sort of works. When I send
the SIGTERM (with the kill command), nothing happens, but as soon as I
invoke any event in my app (click on any button, for example), then my
handler is called and the app shuts down nicely.

Is there some step or method I'm missing?

Thanks in advance.

Justin

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org

Justin Donnelly wrote:

I'm trying to find a way to gracefully handle SIGTERM in my wxPython
app under Linux. I'd like to call Close() on my main frame from
somewhere so that its OnClose method can close a file. Although some
sources seem to indicate that sys.exitfunc or atexit will work when
SIGTERM is received, those handlers don't seem to get called and I
just see "Terminated" on the console. I also tried setting up a
signal handler using signal.signal. This sort of works. When I send
the SIGTERM (with the kill command), nothing happens, but as soon as I
invoke any event in my app (click on any button, for example), then my
handler is called and the app shuts down nicely.

Is there some step or method I'm missing?

IIRC the GTK lib sets up some signal handlers for itself, so perhaps there is a conflict with what you are doing. OTOH, it sounds like that isn't the case for SIGTERM. Is it the signal handler function that is not called until there is an event, or is it the EVT_CLOSE handler that isn't called until after the next event? If the latter then you can try calling wx.WakeUpIdle() from your signal handler to tickle the gui a little so it will process pending top-level window destructions. Or you could use wx.CallAfter from the signal handler to invoke frame.Close (or whatever you need to do) in the next idle event, as it calls wx.WakeUpIdle for you.

···

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