Python Forum

Full Version: something i noticed about the "schedule" module
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
im new to python. using 3.7 atm. i just finished a SCADA auto fault reporting script (works off of a monitoring website's frontend). i've scheduled the program to run every 30 minutes.
schedule.every(30).minutes.run(abcd_1)
but i noticed that it the timer for 30 minutes only starts after the program has run its course. so if the first instance starts at 9:00, the second one will start at 9:32, then 10:04, 10:36 etc. is there a way to have the script run at every 30 minute mark accurately without resorting to writhing
schedule.every().day.at("9:00").do(abcd_1)
48 times?
I guess you refer to schedule module from PyPI.
You can check their answer to your question:
Quote:How can I make sure long-running jobs are always executed on time?

Schedule does not account for the time it takes the job function to execute. To guarantee a stable execution schedule you need to move long-running jobs off the main-thread (where the scheduler runs). See “How to execute jobs in parallel?” in the FAQ for a sample implementation.
Another option is to look at APScheduler package which has BackgroundScheduler
Yet another approach is to use OS scheduler tool like cron or TaskScheduler.
And finally, to be technically correct to schedule each job separately will take 2 or max 3 lines with a loop, no need of 48 lines. :-)