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


Python Scheduler.add_listener方法代码示例

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


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

示例1: test_scheduler_listener

# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import add_listener [as 别名]
    def test_scheduler_listener(self):
        scheduler = Scheduler()

        listener = SchedulerTestListener('test_event')

        scheduler.add_listener(listener)

        self.assertEqual(scheduler.schedule(),'idle')

        event = Event(time(),'test_event')

        self.assertEqual(scheduler.schedule([event]),event)

        self.assertEqual(listener.count,1)
开发者ID:sonologic,项目名称:thermo2,代码行数:16,代码来源:test_scheduler.py

示例2: test_scheduler_timed_listener

# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import add_listener [as 别名]
    def test_scheduler_timed_listener(self):
        scheduler = Scheduler()

        listener = SchedulerTestListener('test_event')

        scheduler.add_listener(listener)

        scheduler.add_timer(0.250,'test_event')

        start = time()
        count = 0

        while time() < start+1.05:
            event = scheduler.schedule()
    
            if event!='idle' and event.label == 'test_event':
                count = count + 1
            sleep(0.05)

        self.assertEqual(count,4)
        self.assertEqual(listener.count,4)
开发者ID:sonologic,项目名称:thermo2,代码行数:23,代码来源:test_scheduler.py

示例3: SchedulerTest

# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import add_listener [as 别名]
class SchedulerTest(unittest.TestCase):

    def test_scheduler_schedule(self):
        self.scheduler = Scheduler()
        self.assertEqual(self.scheduler.schedule(),'idle')

    def test_scheduler_insert_event(self):
        scheduler = Scheduler()
        
        t = time()
        while time() < t+1:
            self.assertEqual(scheduler.schedule(),'idle')
            sleep(0.05)
     
        event = Event(time(), 'test_event')
        self.assertEqual(scheduler.schedule([event]),event)

    def test_scheduler_add_timer(self):
        self.scheduler = Scheduler()

        self.scheduler.add_timer(2, 'test_timer')

        self.assertEqual(len(self.scheduler.timers),1);

        self.assertTrue('test_timer' in self.scheduler.timers.keys())

        self.assertEqual(self.scheduler.timers['test_timer'].getPeriod(),2)

    def test_scheduler_timer(self):
        self.scheduler = Scheduler()
        error = 0.1
        delay = 2

        startTime = time()
        self.scheduler.add_timer(delay,'test_timer')
        while time() < startTime+delay-error:
            self.assertEqual(self.scheduler.schedule(),'idle')
            sleep(error/10)

        event_count = 0

        while time() < startTime+delay+error:
            event = self.scheduler.schedule()

            if event!='idle' and event.label=='test_timer':
                event_count = event_count + 1
            sleep(error/10)

        self.assertEqual(event_count,1)

    def test_scheduler_add_listener(self):
        self.scheduler = Scheduler()

        listener = SchedulerTestListener('foo')

        self.scheduler.add_listener(listener)

        self.assertEqual(len(self.scheduler.listeners),1)
        self.assertEqual(self.scheduler.listeners['foo'],[listener])

    def test_scheduler_add_bad_listener(self):
        self.scheduler = Scheduler()

        listener = SchedulerTestListener('foo')
        listener.addEvent(None)

        type_error = False

        try:
            self.scheduler.add_listener(listener)
        except TypeError:
            type_error = True

        self.assertEqual(type_error,True)

    def test_scheduler_listener(self):
        scheduler = Scheduler()

        listener = SchedulerTestListener('test_event')

        scheduler.add_listener(listener)

        self.assertEqual(scheduler.schedule(),'idle')

        event = Event(time(),'test_event')

        self.assertEqual(scheduler.schedule([event]),event)

        self.assertEqual(listener.count,1)

    def test_scheduler_timed_listener(self):
        scheduler = Scheduler()

        listener = SchedulerTestListener('test_event')

        scheduler.add_listener(listener)

        scheduler.add_timer(0.250,'test_event')

        start = time()
#.........这里部分代码省略.........
开发者ID:sonologic,项目名称:thermo2,代码行数:103,代码来源:test_scheduler.py


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