python - wxPython handling SIGTERM / SIGINT -
i have wxpython app. want respond sigterm , sigint if "close" button had been clicked. however, when bind signals using signal.signal(signal.sigterm, exit_handler), executed after event sent main app graphically (clicking on button, opening menu, etc.). how can avoid , execute handles event 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 if signal calls moved outside function , executed before wx calls.
one way of doing it, add 'timer' fake event.
import wx import signal, os def signalusr1_handler(sig,frame): print "signal caught" class exampleframe(wx.frame): def __init__(self, parent): wx.frame.__init__(self, parent) pid_no = str(os.getpid()) panel = wx.panel(self) self.quote1 = wx.statictext(panel, label="test signal timer", pos=(20, 30)) self.quote2 = wx.statictext(panel, label="send process usr1 signal", pos=(20, 50)) self.quote3 = wx.statictext(panel, label="kill -s usr1 "+pid_no, pos=(20, 70)) self.button = wx.button(panel, -1, "click", pos=(20,90)) self.button.bind(wx.evt_button, self.onpress) self.timer = wx.timer(self) self.bind(wx.evt_timer, self.ontimer, self.timer) self.timer.start(1000) self.show() def onpress(self, event): print "button pressed" def ontimer(self, event): return app = wx.app() exampleframe(none) signal.signal(signal.sigusr1,signalusr1_handler) app.mainloop()
Comments
Post a Comment