本文整理汇总了Python中tornado.concurrent.TracebackFuture.exception方法的典型用法代码示例。如果您正苦于以下问题:Python TracebackFuture.exception方法的具体用法?Python TracebackFuture.exception怎么用?Python TracebackFuture.exception使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.concurrent.TracebackFuture
的用法示例。
在下文中一共展示了TracebackFuture.exception方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: AsyncResult
# 需要导入模块: from tornado.concurrent import TracebackFuture [as 别名]
# 或者: from tornado.concurrent.TracebackFuture import exception [as 别名]
class AsyncResult(object):
"""
Essentially a wrapper for a Tornado TracebackFuture
"""
def __init__(self, future=None):
if future is not None:
self._future = future
else:
self._future = TracebackFuture()
self._future.add_done_callback(functools.partial(async_result_complete, self))
self._condition = threading.Condition()
def ready(self):
"""Return `True` if and only if it holds a value or an
exception"""
return self._future.done()
def successful(self):
"""Return `True` if and only if it is ready and holds a
value"""
return self._future.exception() is None
@property
def exception(self):
return self._future.exception()
def set(self, value=None):
"""Store the value. Wake up the waiters.
:param value: Value to store as the result.
Any waiters blocking on :meth:`get` or :meth:`wait` are woken
up. Sequential calls to :meth:`wait` and :meth:`get` will not
block at all."""
with self._condition:
self._future.set_result(value)
def set_exception(self, exception):
"""Store the exception. Wake up the waiters.
:param exception: Exception to raise when fetching the value.
Any waiters blocking on :meth:`get` or :meth:`wait` are woken
up. Sequential calls to :meth:`wait` and :meth:`get` will not
block at all."""
with self._condition:
self._future.set_exception(exception)
def get(self, block=True, timeout=None):
"""Return the stored value or raise the exception
:param block: Whether this method should block or return
immediately.
:type block: bool
:param timeout: How long to wait for a value when `block` is
`True`.
:type timeout: float
If this instance already holds a value / an exception, return /
raise it immediately. Otherwise, block until :meth:`set` or
:meth:`set_exception` has been called or until the optional
timeout occurs."""
with self._condition:
if self.ready():
return self._future.result()
elif block:
self._condition.wait(timeout)
return self._future.result()
# if we get to this point we timeout
raise KazooTimeoutError()
def get_nowait(self):
"""Return the value or raise the exception without blocking.
If nothing is available, raise the Timeout exception class on
the associated :class:`IHandler` interface."""
return self._future.result()
def wait(self, timeout=None):
"""Block until the instance is ready.
:param timeout: How long to wait for a value
:type timeout: float
If this instance already holds a value / an exception, return /
raise it immediately. Otherwise, block until :meth:`set` or
:meth:`set_exception` has been called or until the optional
timeout occurs."""
with self._condition:
self._condition.wait(timeout)
return self.ready()
def rawlink(self, callback):
"""Register a callback to call when a value or an exception is
set
:param callback:
A callback function to call after :meth:`set` or
:meth:`set_exception` has been called. This function will
#.........这里部分代码省略.........