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


Python gen.Multi方法代码示例

本文整理汇总了Python中tornado.gen.Multi方法的典型用法代码示例。如果您正苦于以下问题:Python gen.Multi方法的具体用法?Python gen.Multi怎么用?Python gen.Multi使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.gen的用法示例。


在下文中一共展示了gen.Multi方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_multi_exceptions

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import Multi [as 别名]
def test_multi_exceptions(self):
        with ExpectLog(app_log, "Multiple exceptions in yield list"):
            with self.assertRaises(RuntimeError) as cm:
                yield gen.Multi([self.async_exception(RuntimeError("error 1")),
                                 self.async_exception(RuntimeError("error 2"))])
        self.assertEqual(str(cm.exception), "error 1")

        # With only one exception, no error is logged.
        with self.assertRaises(RuntimeError):
            yield gen.Multi([self.async_exception(RuntimeError("error 1")),
                             self.async_future(2)])

        # Exception logging may be explicitly quieted.
        with self.assertRaises(RuntimeError):
            yield gen.Multi([self.async_exception(RuntimeError("error 1")),
                             self.async_exception(RuntimeError("error 2"))],
                            quiet_exceptions=RuntimeError) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:19,代码来源:gen_test.py

示例2: test_multi_dict

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import Multi [as 别名]
def test_multi_dict(self):
        @gen.engine
        def f():
            (yield gen.Callback("k1"))("v1")
            (yield gen.Callback("k2"))("v2")
            results = yield dict(foo=gen.Wait("k1"), bar=gen.Wait("k2"))
            self.assertEqual(results, dict(foo="v1", bar="v2"))
            self.stop()
        self.run_gen(f)

    # The following tests explicitly run with both gen.Multi
    # and gen.multi_future (Task returns a Future, so it can be used
    # with either). 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:15,代码来源:gen_test.py

示例3: test_multi_yieldpoint_delayed

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import Multi [as 别名]
def test_multi_yieldpoint_delayed(self):
        @gen.engine
        def f():
            # callbacks run at different times
            responses = yield gen.Multi([
                gen.Task(self.delay_callback, 3, arg="v1"),
                gen.Task(self.delay_callback, 1, arg="v2"),
            ])
            self.assertEqual(responses, ["v1", "v2"])
            self.stop()
        self.run_gen(f) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:13,代码来源:gen_test.py

示例4: test_multi_yieldpoint_dict_delayed

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import Multi [as 别名]
def test_multi_yieldpoint_dict_delayed(self):
        @gen.engine
        def f():
            # callbacks run at different times
            responses = yield gen.Multi(dict(
                foo=gen.Task(self.delay_callback, 3, arg="v1"),
                bar=gen.Task(self.delay_callback, 1, arg="v2"),
            ))
            self.assertEqual(responses, dict(foo="v1", bar="v2"))
            self.stop()
        self.run_gen(f) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:13,代码来源:gen_test.py

示例5: test_multi_exceptions

# 需要导入模块: from tornado import gen [as 别名]
# 或者: from tornado.gen import Multi [as 别名]
def test_multi_exceptions(self):
        with ExpectLog(app_log, "Multiple exceptions in yield list"):
            with self.assertRaises(RuntimeError) as cm:
                yield gen.Multi(
                    [
                        self.async_exception(RuntimeError("error 1")),
                        self.async_exception(RuntimeError("error 2")),
                    ]
                )
        self.assertEqual(str(cm.exception), "error 1")

        # With only one exception, no error is logged.
        with self.assertRaises(RuntimeError):
            yield gen.Multi(
                [self.async_exception(RuntimeError("error 1")), self.async_future(2)]
            )

        # Exception logging may be explicitly quieted.
        with self.assertRaises(RuntimeError):
            yield gen.Multi(
                [
                    self.async_exception(RuntimeError("error 1")),
                    self.async_exception(RuntimeError("error 2")),
                ],
                quiet_exceptions=RuntimeError,
            ) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:28,代码来源:gen_test.py


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