.. autoexception:: Return
.. autofunction:: with_timeout
- .. autoexception:: TimeoutError
.. autofunction:: sleep
Tornado, just use `~.Semaphore.acquire`.
Toro's ``Event.wait`` raised a ``Timeout`` exception after a timeout. In
-Tornado, `.Event.wait` raises `tornado.gen.TimeoutError`.
+Tornado, `.Event.wait` raises ``tornado.gen.TimeoutError``.
Toro's ``Condition.wait`` also raised ``Timeout``, but in Tornado, the `.Future`
returned by `.Condition.wait` resolves to False after a timeout::
from tornado.ioloop import IOLoop
from tornado.log import app_log
from tornado import stack_context
-from tornado.util import PY3, raise_exc_info
+from tornado.util import PY3, raise_exc_info, TimeoutError
try:
try:
pass
-class TimeoutError(Exception):
- """Exception raised by ``with_timeout``."""
-
-
def _value_from_stopiteration(e):
try:
# StopIteration has a value attribute beginning in py33.
def with_timeout(timeout, future, quiet_exceptions=()):
"""Wraps a `.Future` (or other yieldable object) in a timeout.
- Raises `TimeoutError` if the input future does not complete before
- ``timeout``, which may be specified in any form allowed by
- `.IOLoop.add_timeout` (i.e. a `datetime.timedelta` or an absolute time
- relative to `.IOLoop.time`)
+ Raises `tornado.util.TimeoutError` if the input future does not
+ complete before ``timeout``, which may be specified in any form
+ allowed by `.IOLoop.add_timeout` (i.e. a `datetime.timedelta` or
+ an absolute time relative to `.IOLoop.time`)
If the wrapped `.Future` fails after it has timed out, the exception
will be logged unless it is of a type contained in ``quiet_exceptions``
from tornado.log import app_log, gen_log
from tornado.platform.auto import set_close_exec, Waker
from tornado import stack_context
-from tornado.util import PY3, Configurable, errno_from_exception, timedelta_to_seconds
+from tornado.util import PY3, Configurable, errno_from_exception, timedelta_to_seconds, TimeoutError
try:
import signal
_POLL_TIMEOUT = 3600.0
-class TimeoutError(Exception):
- pass
-
-
class IOLoop(Configurable):
"""A level-triggered I/O loop.
The keyword-only argument ``timeout`` may be used to set
a maximum duration for the function. If the timeout expires,
- a `TimeoutError` is raised.
+ a `tornado.util.TimeoutError` is raised.
This method is useful in conjunction with `tornado.gen.coroutine`
to allow asynchronous calls in a ``main()`` function::
# Wait up to 1 second.
yield condition.wait(timeout=datetime.timedelta(seconds=1))
- The method raises `tornado.gen.TimeoutError` if there's no notification
+ The method raises `tornado.util.TimeoutError` if there's no notification
before the deadline.
"""
def wait(self, timeout=None):
"""Block until the internal flag is true.
- Returns a Future, which raises `tornado.gen.TimeoutError` after a
+ Returns a Future, which raises `tornado.util.TimeoutError` after a
timeout.
"""
if timeout is None:
def acquire(self, timeout=None):
"""Attempt to lock. Returns a Future.
- Returns a Future, which raises `tornado.gen.TimeoutError` after a
+ Returns a Future, which raises `tornado.util.TimeoutError` after a
timeout.
"""
return self._block.acquire(timeout)
def put(self, item, timeout=None):
"""Put an item into the queue, perhaps waiting until there is room.
- Returns a Future, which raises `tornado.gen.TimeoutError` after a
+ Returns a Future, which raises `tornado.util.TimeoutError` after a
timeout.
``timeout`` may be a number denoting a time (on the same
"""Remove and return an item from the queue.
Returns a Future which resolves once an item is available, or raises
- `tornado.gen.TimeoutError` after a timeout.
+ `tornado.util.TimeoutError` after a timeout.
``timeout`` may be a number denoting a time (on the same
scale as `tornado.ioloop.IOLoop.time`, normally `time.time`), or a
def join(self, timeout=None):
"""Block until all items in the queue are processed.
- Returns a Future, which raises `tornado.gen.TimeoutError` after a
+ Returns a Future, which raises `tornado.util.TimeoutError` after a
timeout.
"""
return self._finished.wait(timeout)
pass
else:
import tornado.curl_httpclient
+
+ def test_import_aliases(self):
+ # Ensure we don't delete formerly-documented aliases accidentally.
+ import tornado.ioloop, tornado.gen, tornado.util
+ self.assertIs(tornado.ioloop.TimeoutError, tornado.util.TimeoutError)
+ self.assertIs(tornado.gen.TimeoutError, tornado.util.TimeoutError)
is_finalizing = _get_emulated_is_finalizing()
+class TimeoutError(Exception):
+ """Exception raised by `.with_timeout` and `.IOLoop.run_sync`.
+
+ .. versionchanged:: 5.0:
+ Unified ``tornado.gen.TimeoutError`` and
+ ``tornado.ioloop.TimeoutError`` as ``tornado.util.TimeoutError``.
+ Both former names remain as aliases.
+ """
+
+
class ObjectDict(_ObjectDictBase):
"""Makes a dictionary behave like an object, with attribute-style access.
"""