Example #1
0
    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())
Example #2
0
 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 = []
Example #3
0
File: app.py Project: wmoss/diesel
    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()