本文整理汇总了Python中Timer.call_repeatedly方法的典型用法代码示例。如果您正苦于以下问题:Python Timer.call_repeatedly方法的具体用法?Python Timer.call_repeatedly怎么用?Python Timer.call_repeatedly使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Timer
的用法示例。
在下文中一共展示了Timer.call_repeatedly方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_call_repeatedly
# 需要导入模块: import Timer [as 别名]
# 或者: from Timer import call_repeatedly [as 别名]
def test_call_repeatedly(self):
t = Timer()
try:
t.schedule.enter_after = Mock()
myfun = Mock()
myfun.__name__ = bytes_if_py2('myfun')
t.call_repeatedly(0.03, myfun)
assert t.schedule.enter_after.call_count == 1
args1, _ = t.schedule.enter_after.call_args_list[0]
sec1, tref1, _ = args1
assert sec1 == 0.03
tref1()
assert t.schedule.enter_after.call_count == 2
args2, _ = t.schedule.enter_after.call_args_list[1]
sec2, tref2, _ = args2
assert sec2 == 0.03
tref2.canceled = True
tref2()
assert t.schedule.enter_after.call_count == 2
finally:
t.stop()
示例2: test_call_repeatedly
# 需要导入模块: import Timer [as 别名]
# 或者: from Timer import call_repeatedly [as 别名]
def test_call_repeatedly(self):
t = Timer()
try:
t.schedule.enter_after = Mock()
myfun = Mock()
myfun.__name__ = bytes_if_py2("myfun")
t.call_repeatedly(0.03, myfun)
self.assertEqual(t.schedule.enter_after.call_count, 1)
args1, _ = t.schedule.enter_after.call_args_list[0]
sec1, tref1, _ = args1
self.assertEqual(sec1, 0.03)
tref1()
self.assertEqual(t.schedule.enter_after.call_count, 2)
args2, _ = t.schedule.enter_after.call_args_list[1]
sec2, tref2, _ = args2
self.assertEqual(sec2, 0.03)
tref2.canceled = True
tref2()
self.assertEqual(t.schedule.enter_after.call_count, 2)
finally:
t.stop()