def run(self): """Start up an Application--blocks until the program ends or .halt() is called. """ self._run = True logmod.set_current_application(self) log.info("Starting diesel application") for s in self._services: s.bind_and_listen() self.hub.register(s.sock, s.accept_new_connection, None) for l in self._loops: l.iterate() self.setup() while self._run: try: self.hub.handle_events() except SystemExit: log.warn("-- SystemExit raised.. exiting main loop --") break except KeyboardInterrupt: log.warn("-- KeyboardInterrupt raised.. exiting main loop --") break except Exception, e: log.error("-- Unhandled Exception in main loop --") log.error(traceback.format_exc())
def __init__(self, logger=None, allow_app_replacement=False): assert (allow_app_replacement or runtime.current_app is None), "Only one Application instance per program allowed" runtime.current_app = self self.hub = EventHub() self.waits = WaitPool() self._run = False if logger is None: logger = logmod.Logger() self.logger = logger logmod.set_current_application(self) self._services = [] self._loops = []
def __init__(self, logger=None, allow_app_replacement=False): assert (allow_app_replacement or runtime.current_app is None ), "Only one Application instance per program allowed" runtime.current_app = self self.hub = EventHub() self.waits = WaitPool() self._run = False if logger is None: logger = logmod.Logger() self.logger = logger logmod.set_current_application(self) self._services = [] self._loops = [] self.running = set()