Add comment about (non-)thread-safety of IOLoop.add_timeout.

This commit is contained in:
Ben Darnell 2012-01-02 19:17:57 -08:00
parent 468754e31f
commit ffa8f152ab
1 changed files with 4 additions and 0 deletions

View File

@ -352,6 +352,10 @@ class IOLoop(object):
``deadline`` may be a number denoting a unix timestamp (as returned ``deadline`` may be a number denoting a unix timestamp (as returned
by ``time.time()`` or a ``datetime.timedelta`` object for a deadline by ``time.time()`` or a ``datetime.timedelta`` object for a deadline
relative to the current time. relative to the current time.
Note that it is not safe to call `add_timeout` from other threads.
Instead, you must use `add_callback` to transfer control to the
IOLoop's thread, and then call `add_timeout` from there.
""" """
timeout = _Timeout(deadline, stack_context.wrap(callback)) timeout = _Timeout(deadline, stack_context.wrap(callback))
heapq.heappush(self._timeouts, timeout) heapq.heappush(self._timeouts, timeout)