@classmethod defconfigurable_default(cls): ifhasattr(select, "epoll"): from tornado.platform.epoll import EPollIOLoop return EPollIOLoop ifhasattr(select, "kqueue"): #python 2.6+ on BSD or Mac from tornado.platform.kqueue import KQueueIOLoop return KQueueIOLoop from tornado.platform.select import SelectIOLoop return SelectIOLoop
def start(self): if not logging.getLogger().handlers: logging.basicConfig if self._stopped: self._stopped = False return old_current = getattr(IOLoop._current, "instance", None) IOLoop._current.instance = self self._thread_ident = thread.get_ident() #Return the ‘thread identifier’ of the current thread. This is a nonzero integer self._running = True
old_wakeup_fd = None if hasattr(singal, 'set_wakeup_fd') and os.name == 'posix': try: old_wakeup_fd = signal.set_wakeup_fd(self._waker.write_fileno()) if old_wakeup_fd != -1: signal.set_walkeup_fd(old_wakeup_fd) old_walkup_fd = None except ValueError: pass
while True: poll_timeout = _POLL_TIMEOUT #Prevent IO event starvation by delaying new callbacks # to the next iteration of the event loop. with self._callback_lock: callbacks = self._callbacks self._callbacks = [] for callback in callbacks: self._run_callback(callback) # Closures may be holding on to a lot of memory, so allow # them to be freed before we go into our poll wait. callbacks = callback = None
if self._timeouts: now = self.time() while self_timeouts: if self._timesouts[0].callback is None: # the timeout was cancelled heapq.heappop(self._timeouts) self._cancellations -= 1 elif self._timeouts[0].deadline <= now: timeout = heapq.heappop(self._timeouts) self._run_callback(timeout.callback) del timeout else: seconds = self._timeouts[0].deadline - now poll_timeout = min(seconds, poll_timeout) break