I am using the python schedule module to run a task periodically and I think I ran into a problem.
I believe that it relies on the time of the system on which the python script is running. For example, let's say that I want to run a task every 5 seconds. If I forward the system time, the scheduled task will run as expected. However, if I rewind the system time to, say, 1 day, then the next scheduled task will be completed in 5 seconds + 1 day.
If you run the script below and then change the system time to a few days ago, you can reproduce the problem. The problem can be reproduced on Linux and Windows.
import sched import time import threading period = 5 scheduler = sched.scheduler(time.time, time.sleep) def check_scheduler(): print time.time() scheduler.enter(period, 1, check_scheduler, ()) if __name__ == '__main__': print time.time() scheduler.enter(period, 1, check_scheduler, ()) thread = threading.Thread(target=scheduler.run) thread.start() thread.join() exit(0)
Does anyone have a python solution around this problem?
source share