From: robk-tahoe Date: Thu, 6 Mar 2008 22:09:04 +0000 (-0700) Subject: macapp: simplify node startup failure reporting X-Git-Tag: allmydata-tahoe-0.9.0~57 X-Git-Url: https://git.rkrishnan.org/components/%22news.html/reliability?a=commitdiff_plain;h=6177a958d0990e270f2c080f4237a3614dd5e7d3;p=tahoe-lafs%2Ftahoe-lafs.git macapp: simplify node startup failure reporting 1. changed the node's exit-on-error behaviour. rather than logging debug and then delegating to self for _abort_process() instead simply delegate to self _service_startup_failed(failure) to report failures in the startup deferred chain. subclasses then have complete control of handling and reporting any failures in node startup. 2. replace the convoluted wx.PostEvent() glue for posting an event into the gui thread with the simpler expedient of wx.CallAfter() which is much like foolscap's eventually() but also thread safe for inducing a call back on the gui thread. --- diff --git a/src/allmydata/gui/macapp.py b/src/allmydata/gui/macapp.py index 34176b64..cb31eeca 100644 --- a/src/allmydata/gui/macapp.py +++ b/src/allmydata/gui/macapp.py @@ -43,22 +43,19 @@ def run_macapp(): app = App(basedir) return app.run() -ABORT_EVENT_ID = wx.NewId() - -class AbortEvent(wx.PyEvent): - def __init__(self, failure): - wx.PyEvent.__init__(self) - self.SetEventType(ABORT_EVENT_ID) - self.failure = failure - class MacGuiClient(client.Client): def __init__(self, basedir, app): self.app = app client.Client.__init__(self, basedir) - def _abort_process(self, failure): - event = AbortEvent(failure) - wx.PostEvent(self.app.guiapp.frame, event) + def _service_startup_failed(self, failure): + wx.CallAfter(self.wx_abort, failure) + log.msg('node service startup failed') + log.err(failure) + + def wx_abort(self, failure): + wx.MessageBox(failure.getTraceback(), 'Fatal Error in Node startup') + self.app.guiapp.ExitMainLoop() class App(object): def __init__(self, basedir): @@ -194,9 +191,8 @@ ACCOUNT_PAGE_ID = wx.NewId() MOUNT_ID = wx.NewId() class SplashFrame(wx.Frame): - def __init__(self, app): + def __init__(self): wx.Frame.__init__(self, None, -1, 'Allmydata Tahoe') - self.app = app self.SetSizeHints(100, 100, 600, 800) self.SetIcon(amdicon.getIcon()) @@ -215,16 +211,9 @@ class SplashFrame(wx.Frame): self.Fit() self.Layout() - # plumb up event handler for abort - self.Connect(-1, -1, ABORT_EVENT_ID, self.wx_abort) - def on_close(self, event): self.Show(False) - def wx_abort(self, event): - wx.MessageBox(event.failure.getTraceback(), 'Fatal Error in Node startup') - self.app.ExitMainLoop() - class SplashPanel(wx.Panel): def __init__(self, parent, on_close): wx.Panel.__init__(self, parent, -1) @@ -395,7 +384,7 @@ class MacGuiApp(wx.App): def OnInit(self): try: - self.frame = SplashFrame(self) + self.frame = SplashFrame() self.frame.Show(True) self.SetTopWindow(self.frame) diff --git a/src/allmydata/node.py b/src/allmydata/node.py index 5ce189ec..1bb9d708 100644 --- a/src/allmydata/node.py +++ b/src/allmydata/node.py @@ -166,18 +166,16 @@ class Node(service.MultiService): self._tub_ready_observerlist.fire(self) return self d.addCallback(_ready) - def _die(failure): - self.log('_startService() failed') - log.err(failure) - print "Node._startService failed, aborting" - print failure - #reactor.stop() # for unknown reasons, reactor.stop() isn't working. [ ] TODO - self._abort_process(failure) - d.addErrback(_die) - - def _abort_process(self, failure): + d.addErrback(self._service_startup_failed) + + def _service_startup_failed(self, failure): + self.log('_startService() failed') + log.err(failure) + print "Node._startService failed, aborting" + print failure + #reactor.stop() # for unknown reasons, reactor.stop() isn't working. [ ] TODO self.log('calling os.abort()') - log('calling os.abort()') + log.msg('calling os.abort()') print "calling os.abort()" os.abort()