当前位置: 首页>>代码示例>>Python>>正文


Python gen.BadYieldError方法代码示例

本文整理汇总了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) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:26,代码来源:ioloop.py

示例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) 
开发者ID:tp4a,项目名称:teleport,代码行数:26,代码来源:ioloop.py

示例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) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:7,代码来源:gen_test.py

示例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) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:7,代码来源:gen_test.py

示例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 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:locks_test.py

示例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 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:8,代码来源:locks_test.py

示例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) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:31,代码来源:ioloop.py

示例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) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:8,代码来源:gen_test.py

示例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) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:8,代码来源:gen_test.py


注:本文中的tornado.gen.BadYieldError方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。