本文整理汇总了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)