本文整理汇总了Python中scheduler.Scheduler.do_now方法的典型用法代码示例。如果您正苦于以下问题:Python Scheduler.do_now方法的具体用法?Python Scheduler.do_now怎么用?Python Scheduler.do_now使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类scheduler.Scheduler
的用法示例。
在下文中一共展示了Scheduler.do_now方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_do_now
# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import do_now [as 别名]
def test_do_now(self):
# If I schedule something now, it happens in the zeroth clock and then it
# exits
s = Scheduler()
s.do_now((lambda: None))
iterator = s.run()
self.assertEqual(iterator.next(), 0)
self.assertRaises(StopIteration, iterator.next)
示例2: test_do_later
# 需要导入模块: from scheduler import Scheduler [as 别名]
# 或者: from scheduler.Scheduler import do_now [as 别名]
def test_do_later(self):
# If I schedule something later, it happens after something which happens
# now
now_called = [False]
def for_now(): now_called[0] = True
later_called = [False]
def for_later(): later_called[0] = True
much_later_called = [False]
def for_much_later(): much_later_called[0] = True
s = Scheduler()
s.do_now(for_now)
s.do_later(for_later)
s.do_later(for_much_later, 10)
iterator = s.run()
self.assertTrue( not now_called[0]
and not later_called[0]
and not much_later_called[0])
self.assertEqual(iterator.next(), 0)
self.assertTrue( now_called[0]
and not later_called[0]
and not much_later_called[0])
self.assertEqual(iterator.next(), 0)
self.assertTrue( now_called[0]
and later_called[0]
and not much_later_called[0])
self.assertEqual(iterator.next(), 10)
self.assertTrue( now_called[0]
and later_called[0]
and much_later_called[0])
self.assertRaises(StopIteration, iterator.next)