import os
import logging
import select
+import thread
import time
import traceback
self._timeouts = []
self._running = False
self._stopped = False
+ self._thread_ident = None
self._blocking_signal_threshold = None
# Create a pipe that we send bogus data to when we want to wake
def close(self, all_fds=False):
"""Closes the IOLoop, freeing any resources used.
-
+
If ``all_fds`` is true, all file descriptors registered on the
IOLoop will be closed (not just the ones created by the IOLoop itself.
"""
if self._stopped:
self._stopped = False
return
+ self._thread_ident = thread.get_ident()
self._running = True
while True:
# Never use an infinite timeout here - it can stall epoll
The argument is a handle as returned by add_timeout.
"""
# Removing from a heap is complicated, so just leave the defunct
- # timeout object in the queue (see discussion in
+ # timeout object in the queue (see discussion in
# http://docs.python.org/library/heapq.html).
# If this turns out to be a problem, we could add a garbage
# collection pass whenever there are too many dead timeouts.
from that IOLoop's thread. add_callback() may be used to transfer
control from other threads to the IOLoop's thread.
"""
- if not self._callbacks:
+ if not self._callbacks and thread.get_ident() != self._thread_ident:
self._wake()
self._callbacks.append(stack_context.wrap(callback))
# Comparison methods to sort by deadline, with object id as a tiebreaker
# to guarantee a consistent ordering. The heapq module uses __le__
# in python2.5, and __lt__ in 2.6+ (sort() and most other comparisons
- # use __lt__).
+ # use __lt__).
def __lt__(self, other):
return ((self.deadline, id(self)) <
(other.deadline, id(other)))