本文整理匯總了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()