Make EventLoop set a Future exception on timeout.

This commit is contained in:
Shiz 2014-02-18 23:57:18 +01:00
parent 6295843fb2
commit 37dd569f26
1 changed files with 2 additions and 7 deletions

View File

@ -15,11 +15,6 @@ FUTURE_TIMEOUT = 30
class Future(tornado.concurrent.TracebackFuture):
""" A future. """
class FutureTimeout:
""" A timeout has occurred when trying to resolve the future. """
def __bool__(self):
return False
def coroutine(func):
""" Decorator for coroutine functions that need to block for asynchronous operations. """
@ -193,10 +188,10 @@ class EventLoop:
def _do_on_future(self, callback, args, kwargs, future):
# This was a time-out.
if not future.done():
future.set_result(FutureTimeout)
future.set_exception(TimeoutError('Future timed out before yielding a result.'))
del self._future_timeouts[future]
# This was a time-out that already has been handled.
elif future.result() == FutureTimeout:
elif isinstance(future.exception(), TimeoutError):
return
# A regular result. Cancel the timeout.
else: