def run(self, savelist=[], exc_handler=None): self._savelist = savelist if self._savelist: self._stid = add_timer(5, self.save_states) while self.map and not self.stopped(): try: asyncore.loop(0.5, False, self.map, 1) run_timers() except KeyboardInterrupt, ke: for t in self.map.values(): t.session.stop() # break except Exception, exc: #logging.debug("reaktor loop: %s", type(exc)) #logging.debug(traceback.format_exc()) if exc_handler is not None: if not exc_handler(exc): break else: # what to do?? pass
def run(self): """Run the application data receiving loop. This is executed in the subprocess context. """ signal.signal(signal.SIGTERM, self.sigterm) logging.debug("starting subprocess in pid: %d [fd %d]", os.getpid(), self.conn.fileno()) # flush all timers as we are running in separate process flush_timers() os.closerange(3, self.conn.fileno()) self.init = getattr(self.target, 'setup', None) self.finish = getattr(self.target, 'finish', None) if hasattr(self.target, 'handle'): self.handler = getattr(self.target, 'handle') else: self.handler = target if not callable(self.handler): raise ConfigError(self, exc.E_NOTCALLABLE) if callable(self.init): self.init(self.conn, self.config) self.running = True while self.running: try: readable = self.conn.poll(0.5) run_timers() if not readable: continue data = self.conn.recv() except (IOError, KeyboardInterrupt), ex: break except Exception, e: logging.error("Subprocess recv failed: %s", str(e)) break