本文整理匯總了Python中tornado.gen.BadYieldError方法的典型用法代碼示例。如果您正苦於以下問題:Python gen.BadYieldError方法的具體用法?Python gen.BadYieldError怎麽用?Python gen.BadYieldError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類tornado.gen
的用法示例。
在下文中一共展示了gen.BadYieldError方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: _run_callback
# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def _run_callback(self, callback):
"""Runs a callback with error handling.
For use in subclasses.
"""
try:
ret = callback()
if ret is not None:
from tornado import gen
# Functions that return Futures typically swallow all
# exceptions and store them in the Future. If a Future
# makes it out to the IOLoop, ensure its exception (if any)
# gets logged too.
try:
ret = gen.convert_yielded(ret)
except gen.BadYieldError:
# It's not unusual for add_callback to be used with
# methods returning a non-None and non-yieldable
# result, which should just be ignored.
pass
else:
self.add_future(ret, lambda f: f.result())
except Exception:
self.handle_callback_exception(callback)
示例2: _run_callback
# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def _run_callback(self, callback):
"""Runs a callback with error handling.
For use in subclasses.
"""
try:
ret = callback()
if ret is not None:
from tornado import gen
# Functions that return Futures typically swallow all
# exceptions and store them in the Future. If a Future
# makes it out to the IOLoop, ensure its exception (if any)
# gets logged too.
try:
ret = gen.convert_yielded(ret)
except gen.BadYieldError:
# It's not unusual for add_callback to be used with
# methods returning a non-None and non-yieldable
# result, which should just be ignored.
pass
else:
self.add_future(ret, self._discard_future_result)
except Exception:
self.handle_callback_exception(callback)
示例3: test_bogus_yield
# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def test_bogus_yield(self):
@gen.engine
def f():
yield 42
self.assertRaises(gen.BadYieldError, self.run_gen, f)
示例4: test_bogus_yield_tuple
# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def test_bogus_yield_tuple(self):
@gen.engine
def f():
yield (1, 2)
self.assertRaises(gen.BadYieldError, self.run_gen, f)
示例5: test_yield_sem
# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def test_yield_sem(self):
# Ensure we catch a "with (yield sem)", which should be
# "with (yield sem.acquire())".
with self.assertRaises(gen.BadYieldError):
with (yield locks.Semaphore()):
pass
示例6: test_yield_lock
# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def test_yield_lock(self):
# Ensure we catch a "with (yield lock)", which should be
# "with (yield lock.acquire())".
with self.assertRaises(gen.BadYieldError):
with (yield locks.Lock()):
pass
示例7: _run_callback
# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def _run_callback(self, callback: Callable[[], Any]) -> None:
"""Runs a callback with error handling.
.. versionchanged:: 6.0
CancelledErrors are no longer logged.
"""
try:
ret = callback()
if ret is not None:
from tornado import gen
# Functions that return Futures typically swallow all
# exceptions and store them in the Future. If a Future
# makes it out to the IOLoop, ensure its exception (if any)
# gets logged too.
try:
ret = gen.convert_yielded(ret)
except gen.BadYieldError:
# It's not unusual for add_callback to be used with
# methods returning a non-None and non-yieldable
# result, which should just be ignored.
pass
else:
self.add_future(ret, self._discard_future_result)
except asyncio.CancelledError:
pass
except Exception:
app_log.error("Exception in callback %r", callback, exc_info=True)
示例8: test_bogus_yield
# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def test_bogus_yield(self):
@gen.coroutine
def f():
yield 42
self.assertRaises(gen.BadYieldError, self.io_loop.run_sync, f)
示例9: test_bogus_yield_tuple
# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import BadYieldError [as 別名]
def test_bogus_yield_tuple(self):
@gen.coroutine
def f():
yield (1, 2)
self.assertRaises(gen.BadYieldError, self.io_loop.run_sync, f)