def start(self, poll_timeout=0.02): """ Start the engine. This method blocks until the engine is stopped. It should be called after your asynchronous application has been fully initialised and is ready to start. Args: poll_timeout: The timeout to pass to engine.poll(). Raises: SystemExit """ if self._shutdown: self._shutdown = False return if self._running: return else: self._running = True # Initialise engine. log.info("Starting engine.") Publisher.instance().publish("pants.engine.start") # Main loop. try: log.info("Entering main loop.") while not self._shutdown: self.poll(poll_timeout) except KeyboardInterrupt: pass except SystemExit: raise except Exception: log.exception("Uncaught exception in main loop.") finally: # Graceful shutdown. log.info("Stopping engine.") Publisher.instance().publish("pants.engine.stop") log.info("Shutting down.") self._shutdown = False self._running = False
"engine", # Core "Client", "Connection", "Server", # Networking "event", "publish", "subscribe", "unsubscribe", # Publisher "callback", "loop", "cycle", "defer", # Scheduling ] ############################################################################### # Properties ############################################################################### #: Alias for pants.engine.Engine.instance engine = Engine.instance() #: Alias for pants.publisher.Publisher.instance publisher = Publisher.instance() ############################################################################### # Functions ############################################################################### #: Alias for pants.publisher.Publisher.instance().event event = publisher.event #: Alias for pants.publisher.Publisher.instance().publish publish = publisher.publish #: Alias for pants.publisher.Publisher.instance().subscribe subscribe = publisher.subscribe