def init(): # bind a ioloop or use default ioloop chronos.setup() # chronos.setup(tornado.ioloop.IOLoop()) chronos.schedule('say', chronos.every_second(1), say) chronos.schedule('say2', chronos.every_second(1), test_process, once=True, process=True) chronos.schedule('say3', chronos.every_second(1), lambda: test("test3")) chronos.start(True)
def test_schedule_process(self): import threading lock = threading.Lock() def say(word="hello chronos"): LOG.info("%s: %d" % (word, say.count)) with lock: if say.count == 5: chronos.stop(True, True) else: say.count += 1 say.count = 1 chronos.schedule('stop', every_second(1), lambda: say("test")) chronos.schedule('test_proc', every_second(1), test_proc, process=True) chronos.start(True) assert say.count == 5
def test_schedule_thread(self): import threading lock = threading.Lock() def say(word="hello chronos"): LOG.info("%s: %d" % (word, say.count)) with lock: if say.count == 5: chronos.remove_task('say2') chronos.stop(True, True) else: say.count += 1 say.count = 1 def say2(word): LOG.info("%s: %d" % (word, say.count)) chronos.schedule('say', every_second(1), lambda: say("test")) chronos.schedule('say2', every_second(1), lambda: say2("test2")) chronos.start(True) assert say.count == 5
def test_builtin_timer_second(self): assert every_second(2).next().total_seconds() == 2 assert every_second(3600).next().total_seconds() == 3600