def _setup_environment(self): """Finish misc startup tasks like starting logging, zipping any crash logs from the last run, installing signal handlers, startup argument handler, etc""" #apply the necessary hacks: Twisted.apply_dns_hack() Twisted.apply_dns_hack2() if System.IS_WINDOWS: Win32HiddenWindowHack.apply() #start listening for connections from any other instances of BitBlinder StartupServer.start() Profiler.start() #Make sure we log ALL exceptions Twisted.install_exception_handlers(self.on_quit_signal) #Set the signal handler for exiting def sig_handler(signum, frame): self.on_quit_signal() signal.signal(signal.SIGTERM, sig_handler) #make the gui: GUIController.start() self.gui = GUIController.get() #do some tests to see how this user's network is configured: NetworkState.test_network_state() #TODO: figure out what needs to change in the wrapper and submit a fix warnings.filterwarnings('ignore', module=".*TwistedProtocolWrapper.*", lineno=447)
def _shutdown(self, result): """Stop the main loop and cause the program to exit. This should ONLY be called after all Applications are shut down cleanly.""" Basic.validate_result(result, "MainLoop::_shutdown") #close the server that listens for new versions of the app to start up: StartupServer.stop() #remove scheduled events: if self.updateEvent and self.updateEvent.active(): self.updateEvent.cancel() ProgramState.DO_UPDATES = False self.updateEvent = None GlobalEvents.throw_event("shutdown") log_msg("Done with shutdown deferreds", 4) #close the main loop if ProgramState.USE_GTK: try: gtk.main_quit() except Exception, error: log_ex(error, "Couldn't kill the gtk main loop")