I have a wxPython app. I want it to respond to SIGTERM and SIGINT just like as if the "close" button had been clicked. However, when I bind the signals using signal.signal(signal.SIGTERM, exit_handler)
, they only get executed after an event is sent to the main app graphically (clicking on a button, opening menu, etc.). How can I avoid this and execute the handles as soon as the event is caught?
Relevant parts of code:
class MyFrame(wx.Frame):
def __init__(self, parent, title):
# ...
self.Bind(wx.EVT_CLOSE, self.signal_handler)
signal.signal(signal.SIGTERM, self.signal_handler)
signal.signal(signal.SIGINT, self.signal_handler)
# ...
app = wx.App(redirect=False, clearSigInt=False)
frame = MyFrame(None, "Hello World")
app.MainLoop()
This happens even if the signal calls are moved outside any function and executed before any wx calls.