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


Python Reactor.mark方法代码示例

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


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

示例1: ExceptionTest

# 需要导入模块: from proton.reactor import Reactor [as 别名]
# 或者: from proton.reactor.Reactor import mark [as 别名]

#.........这里部分代码省略.........
            assert False, "expected to barf"
        except Barf:
            pass

    def test_schedule(self):
        self.reactor.schedule(0, BarfOnTask())
        try:
            self.reactor.run()
            assert False, "expected to barf"
        except Barf:
            pass

    def test_schedule_many_nothings(self):
        class Nothing:
            results = []

            def on_timer_task(self, event):
                self.results.append(None)

        num = 12345
        for a in range(num):
            self.reactor.schedule(0, Nothing())
        self.reactor.run()
        assert len(Nothing.results) == num

    def test_schedule_many_nothing_refs(self):
        class Nothing:
            results = []

            def on_timer_task(self, event):
                self.results.append(None)

        num = 12345
        tasks = []
        for a in range(num):
            tasks.append(self.reactor.schedule(0, Nothing()))
        self.reactor.run()
        assert len(Nothing.results) == num

    def test_schedule_many_nothing_refs_cancel_before_run(self):
        class Nothing:
            results = []

            def on_timer_task(self, event):
                self.results.append(None)

        num = 12345
        tasks = []
        for a in range(num):
            tasks.append(self.reactor.schedule(0, Nothing()))
        for task in tasks:
            task.cancel()
        self.reactor.run()
        assert len(Nothing.results) == 0

    def test_schedule_cancel(self):
        barf = self.reactor.schedule(10, BarfOnTask())

        class CancelBarf:
            def __init__(self, barf):
                self.barf = barf

            def on_timer_task(self, event):
                self.barf.cancel()
                pass

        self.reactor.schedule(0, CancelBarf(barf))
        now = self.reactor.mark()
        try:
            self.reactor.run()
            elapsed = self.reactor.mark() - now
            assert elapsed < 10, "expected cancelled task to not delay the reactor by %s" % elapsed
        except Barf:
            assert False, "expected barf to be cancelled"

    def test_schedule_cancel_many(self):
        num = 12345
        barfs = set()
        for a in range(num):
            barf = self.reactor.schedule(10 * (a + 1), BarfOnTask())

            class CancelBarf:
                def __init__(self, barf):
                    self.barf = barf

                def on_timer_task(self, event):
                    self.barf.cancel()
                    barfs.discard(self.barf)
                    pass

            self.reactor.schedule(0, CancelBarf(barf))
            barfs.add(barf)
        now = self.reactor.mark()
        try:
            self.reactor.run()
            elapsed = self.reactor.mark() - now
            assert elapsed < num, "expected cancelled task to not delay the reactor by %s" % elapsed
            assert not barfs, "expected all barfs to be discarded"
        except Barf:
            assert False, "expected barf to be cancelled"
开发者ID:RobertoMalatesta,项目名称:qpid-proton,代码行数:104,代码来源:reactor.py


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