def loop(self, timeout=None, blocking=True): """Start the asynchronous IO loop. - (float) timeout: the timeout passed to the underlying multiplex syscall (select(), epoll() etc.). - (bool) blocking: if True poll repeatedly, as long as there are registered handlers and/or scheduled functions. If False poll only once and return the timeout of the next scheduled call (if any, else None). """ if not _IOLoop._started_once: _IOLoop._started_once = True if not logging.getLogger().handlers: # If we get to this point it means the user hasn't # configured logging. We want to log by default so # we configure logging ourselves so that it will # print to stderr. _config_logging() if blocking: # localize variable access to minimize overhead poll = self.poll socket_map = self.socket_map tasks = self.sched._tasks sched_poll = self.sched.poll if timeout is not None: #while socket_map: while self.socket_map: poll(timeout) sched_poll() else: soonest_timeout = None #while socket_map: while self.socket_map: poll(soonest_timeout) soonest_timeout = sched_poll() else: sched = self.sched if self.socket_map: self.poll(timeout) if sched._tasks: return sched.poll()