def test_1_sec_callback(self): rt = PeriodicTimer() rt.interval = 1 rt.action(self.callback, ()) rt.start() time.sleep(3) rt.stop() self.assertEqual(self.called, True, "Callback was not called")
def test_2_sec_repeated(self): rt = PeriodicTimer() rt.interval = 2 rt.action(self.callback, ()) rt.start() time.sleep(3) self.assertEqual(self.called, True, "Callback was not called 1st time") self.called = False time.sleep(3) self.assertEqual(self.called, True, "Callback was not called 2nd time")
def start(loop_action=None, loop_time=1, admin_user=None, admin_password=None, telnet_port=None): if loop_action: # run the loop for startup once loop_action(startup=True) # run periodically from now on myLooper = PeriodicTimer(loop_time) # loop every 1 sec myLooper.action(loop_action, None, {'startup': False}) myLooper.start() if telnet_port: from pytomation.utility import Manhole #must be enabled in pytomation.utility.__init__.py Manhole().start(user=admin_user, password=admin_password, port=telnet_port, instances=get_instances_detail()) while True: time.sleep(1)