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


Python async_event_loop.AsyncEventLoop类代码示例

本文整理汇总了Python中botoflow.core.async_event_loop.AsyncEventLoop的典型用法代码示例。如果您正苦于以下问题:Python AsyncEventLoop类的具体用法?Python AsyncEventLoop怎么用?Python AsyncEventLoop使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_two_tasks

 def test_two_tasks(self):
     ev = AsyncEventLoop()
     with ev:
         self.count()
         self.count()
     ev.execute_all_tasks()
     self.assertEqual(2, self.counter)
开发者ID:boto,项目名称:botoflow,代码行数:7,代码来源:test_async_task.py

示例2: test_cancel_only_any

    def test_cancel_only_any(self):
        """
        Test that only futures "in" Any get cancelled if one of them fails
        """
        @coroutine
        def raises():
            raise RuntimeError()

        @coroutine
        def count():
            self.counter += 1

        @coroutine
        def main():
            count()
            try:
                fut1, fut2 = raises(), raises()
                yield AnyFuture(fut1, fut2)
            except RuntimeError:
                yield count()
                try:
                    yield fut1
                except RuntimeError:
                    yield count()

        ev = AsyncEventLoop()
        with ev:
            future = main()
        ev.execute_all_tasks()

        self.assertEqual(3, self.counter)
开发者ID:boto,项目名称:botoflow,代码行数:31,代码来源:test_future.py

示例3: test_catch

    def test_catch(self):

        @coroutine
        def raises():
            raise RuntimeError("TestErr")

        @coroutine
        def count():
            self.counter += 1

        @coroutine
        def echo(inp):
            return inp

        @coroutine
        def main():
            try:
                future = count()
                yield raises()
            except RuntimeError:
                yield count()
                future = echo(1)
                result = yield echo(2)
                if result == 2:
                    self.counter += 1
                result = yield future
                if result == 1:
                    self.counter += 1

        ev = AsyncEventLoop()
        with ev:
            main()
        ev.execute_all_tasks()

        self.assertEqual(4, self.counter)
开发者ID:boto,项目名称:botoflow,代码行数:35,代码来源:test_future.py

示例4: test_simple_class

    def test_simple_class(self):

        class Main(object):

            def __init__(self):
                self.counter = 0

            @coroutine
            def count(self):
                self.counter += 1

            @coroutine
            def count_generator(self):
                if False: yield
                self.counter += 1

            @coroutine
            def main(self):
                future = self.count_generator()
                for i in range(3):
                    yield self.count()
                yield future

        ev = AsyncEventLoop()
        main = Main()
        with ev:
            future = main.main()

        ev.execute_all_tasks()
        self.assertTrue(isinstance(future, BaseFuture))
        self.assertEqual(4, main.counter)
开发者ID:boto,项目名称:botoflow,代码行数:31,代码来源:test_future.py

示例5: test_cancel_only_all

    def test_cancel_only_all(self):
        """
        Test that only futures "in" All get cancelled if one of them fails
        """
        @async
        def raises():
            raise RuntimeError()

        @async
        def count():
            self.counter += 1

        @async
        def main():
            count()
            try:
                yield (raises(), count())
            except RuntimeError:
                yield count()

        ev = AsyncEventLoop()
        with ev:
            future = main()
        ev.execute_all_tasks()

        self.assertEqual(2, self.counter)
开发者ID:notthatbreezy,项目名称:botoflow,代码行数:26,代码来源:test_future.py

示例6: test_except_with_err_subtask

    def test_except_with_err_subtask(self):
        @task
        def count():
            self.counter += 1

        @count.do_finally
        def count():
            self.counter += 1

            @task
            def err():
                raise RuntimeError("Test")
            @err.do_except
            def err(err):
                if isinstance(err, RuntimeError):
                    self.counter += 1

            err()

        ev = AsyncEventLoop()
        with ev:
            count()
        ev.execute_all_tasks()

        self.assertEqual(3, self.counter)
开发者ID:boto,项目名称:botoflow,代码行数:25,代码来源:test_async_task.py

示例7: test_finally_reraise_catch_subtask

    def test_finally_reraise_catch_subtask(self):
        @task
        def count():
            self.counter += 1

        @count.do_finally
        def count():
            self.counter += 1

            @task
            def err():
                raise RuntimeError("Test")

            @err.do_except
            def err(err):
                if isinstance(err, RuntimeError):
                    self.counter += 1
                raise err

            err()

        @task
        def main():
            self.counter +=1
            count()
        @main.do_except
        def main(err):
            self.counter += 1

        ev = AsyncEventLoop()
        with ev:
            main()
        ev.execute_all_tasks()

        self.assertEqual(5, self.counter)
开发者ID:boto,项目名称:botoflow,代码行数:35,代码来源:test_async_task.py

示例8: test_except_and_finally_raise

    def test_except_and_finally_raise(self):
        @task
        def raises():
            raise RuntimeError("Error")
        @raises.do_except
        def raises(err):
            raise err
        @raises.do_finally
        def raises():
            raise ValueError("Finally wins")

        @task
        def main():
            raises()
        @main.do_except
        def main(err):
            if isinstance(err, ValueError):
                self.except_called = True
            elif isinstance(err, RuntimeError):
                self.except_called = False

        ev = AsyncEventLoop()
        with ev:
            main()
        ev.execute_all_tasks()

        self.assertTrue(self.except_called)
开发者ID:boto,项目名称:botoflow,代码行数:27,代码来源:test_async_task.py

示例9: test_cancel_except_finally

    def test_cancel_except_finally(self):
        @task
        def raises():
            raise RuntimeError("Error")

        @task
        def other():
            self.counter -= 1
        @other.do_except
        def other(err):
            if isinstance(err, CancellationError):
                self.counter += 1
        @other.do_finally
        def other():
            self.counter += 1

        @task
        def main():
            raises()
            other()

        @main.do_except
        def main(err):
            self.counter += 1

        ev = AsyncEventLoop()
        with ev:
            main()
        ev.execute_all_tasks()

        self.assertEqual(3, self.counter)
开发者ID:boto,项目名称:botoflow,代码行数:31,代码来源:test_async_task.py

示例10: test_exception

    def test_exception(self):
        future1 = BaseFuture()
        future2 = BaseFuture()

        ev = AsyncEventLoop()
        with ev:
            any_future = AnyFuture(future1, future2)
            future1.set_exception(RuntimeError())

        ev.execute_all_tasks()
        self.assertEqual(type(any_future.exception()), RuntimeError)
开发者ID:boto,项目名称:botoflow,代码行数:11,代码来源:test_future.py

示例11: test_simple

    def test_simple(self):
        future1 = BaseFuture()
        future2 = BaseFuture()

        ev = AsyncEventLoop()
        with ev:
            any_future = AnyFuture(future1, future2)
            future2.set_result(3)

        ev.execute_all_tasks()
        self.assertEqual(any_future.result(), 3)
        self.assertFalse(future1.done())
开发者ID:boto,项目名称:botoflow,代码行数:12,代码来源:test_future.py

示例12: test_no_futures_yield_empty_tuple

    def test_no_futures_yield_empty_tuple(self):
        @coroutine
        def main():
            results = yield AnyFuture()
            return_(results)

        ev = AsyncEventLoop()
        with ev:
            future = main()
        ev.execute_all_tasks()

        self.assertFalse(future.result())
开发者ID:boto,项目名称:botoflow,代码行数:12,代码来源:test_future.py

示例13: test_recursive

    def test_recursive(self):
        ev = AsyncEventLoop()

        @task
        def recursive(ct=10):
            self.counter += 1
            if ct == 1:
                return
            ct -=1
            recursive(ct)

        with ev:
            recursive()
        ev.execute_all_tasks()
        self.assertEqual(10, self.counter)
开发者ID:boto,项目名称:botoflow,代码行数:15,代码来源:test_async_task.py

示例14: test_format

    def test_format(self):
        @task
        def task_func():
            raise RuntimeError("Test")

        @task_func.do_except
        def except_func(err):
            self.tb_str = "".join(format_exc())

        ev = AsyncEventLoop()
        with ev:
            task_func()
        ev.execute_all_tasks()

        self.assertTrue(self.tb_str)
        self.assertEqual(1, self.tb_str.count('---continuation---'))
开发者ID:notthatbreezy,项目名称:botoflow,代码行数:16,代码来源:test_async_traceback.py

示例15: test_future

    def test_future(self):
        future = BaseFuture()
        @task
        def other():
            future.set_result(1)

        @task
        def main():
            other()

        ev = AsyncEventLoop()
        with ev:
            main()
        ev.execute_all_tasks()

        self.assertEqual(1, future.result())
开发者ID:boto,项目名称:botoflow,代码行数:16,代码来源:test_async_task.py


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