當前位置: 首頁>>代碼示例>>Python>>正文


Python gen.multi_future方法代碼示例

本文整理匯總了Python中tornado.gen.multi_future方法的典型用法代碼示例。如果您正苦於以下問題:Python gen.multi_future方法的具體用法?Python gen.multi_future怎麽用?Python gen.multi_future使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在tornado.gen的用法示例。


在下文中一共展示了gen.multi_future方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: test_multi_future_exceptions

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import multi_future [as 別名]
def test_multi_future_exceptions(self):
        with ExpectLog(app_log, "Multiple exceptions in yield list"):
            with self.assertRaises(RuntimeError) as cm:
                yield [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 [self.async_exception(RuntimeError("error 1")),
                   self.async_future(2)]

        # Exception logging may be explicitly quieted.
        with self.assertRaises(RuntimeError):
            yield gen.multi_future(
                [self.async_exception(RuntimeError("error 1")),
                 self.async_exception(RuntimeError("error 2"))],
                quiet_exceptions=RuntimeError) 
開發者ID:tao12345666333,項目名稱:tornado-zh,代碼行數:20,代碼來源:gen_test.py

示例2: test_multi_future_exceptions

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import multi_future [as 別名]
def test_multi_future_exceptions(self):
        with ExpectLog(app_log, "Multiple exceptions in yield list"):
            with self.assertRaises(RuntimeError) as cm:
                yield [
                    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 [self.async_exception(RuntimeError("error 1")), self.async_future(2)]

        # Exception logging may be explicitly quieted.
        with self.assertRaises(RuntimeError):
            yield gen.multi_future(
                [
                    self.async_exception(RuntimeError("error 1")),
                    self.async_exception(RuntimeError("error 2")),
                ],
                quiet_exceptions=RuntimeError,
            ) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:24,代碼來源:gen_test.py

示例3: test_multi_dict

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import multi_future [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

示例4: test_multi_future_delayed

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import multi_future [as 別名]
def test_multi_future_delayed(self):
        @gen.engine
        def f():
            # callbacks run at different times
            responses = yield gen.multi_future([
                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

示例5: test_multi_future_dict_delayed

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import multi_future [as 別名]
def test_multi_future_dict_delayed(self):
        @gen.engine
        def f():
            # callbacks run at different times
            responses = yield gen.multi_future(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

示例6: test_multi_delayed

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import multi_future [as 別名]
def test_multi_delayed(self):
        @gen.coroutine
        def f():
            # callbacks run at different times
            responses = yield gen.multi_future(
                [self.delay(3, "v1"), self.delay(1, "v2")]
            )
            self.assertEqual(responses, ["v1", "v2"])

        self.io_loop.run_sync(f) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:12,代碼來源:gen_test.py

示例7: test_multi_dict_delayed

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import multi_future [as 別名]
def test_multi_dict_delayed(self):
        @gen.coroutine
        def f():
            # callbacks run at different times
            responses = yield gen.multi_future(
                dict(foo=self.delay(3, "v1"), bar=self.delay(1, "v2"))
            )
            self.assertEqual(responses, dict(foo="v1", bar="v2"))

        self.io_loop.run_sync(f) 
開發者ID:opendevops-cn,項目名稱:opendevops,代碼行數:12,代碼來源:gen_test.py

示例8: test_multi_delayed

# 需要導入模塊: from tornado import gen [as 別名]
# 或者: from tornado.gen import multi_future [as 別名]
def test_multi_delayed(self):
        @gen.coroutine
        def f():
            # callbacks run at different times
            responses = yield gen.multi_future([
                self.delay(3, "v1"),
                self.delay(1, "v2"),
            ])
            self.assertEqual(responses, ["v1", "v2"])
        self.io_loop.run_sync(f) 
開發者ID:tp4a,項目名稱:teleport,代碼行數:12,代碼來源:gen_test.py


注:本文中的tornado.gen.multi_future方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。