I am creating a script that has a function that should run every X hour.
One way of doing it seems to be with time.sleep(). Example taken from this Stackoverflow question.
import time
while True:
print "This prints once a minute."
time.sleep(60) # Delay for 1 minute (60 seconds)
The other way seems to be with APScheduler. Example taken from this documentation.
from apscheduler.scheduler import Scheduler
sched = Scheduler()
@sched.interval_schedule(hours=3)
def some_job():
print "Decorated job"
sched.configure(options_from_ini_file)
sched.start()
What is the best way of doing this? What are the pros and cons of the different ways? The script will be a daemon later on if that changes anything.