Call python function at every start of hour

Viewed 61

I would like to execute some functions async in python every start of hour meaning if the hour starts the function should also be called. Is there any module available in python to do this ? Or is there any way to get the built-in callback by using os or sys module in python to my function ?

1 Answers

Check out schedule by dbader, a lightweight python library. I've given some examples of using it below.

import schedule
import time

def job():
    print("I'm working...")

#This will run every hour
schedule.every().hour.do(job)

#Other Examples
schedule.every(10).seconds.do(job)
schedule.every(10).minutes.do(job)
schedule.every().day.at("10:30").do(job)
schedule.every(5).to(10).minutes.do(job)
schedule.every().monday.do(job)
schedule.every().wednesday.at("13:15").do(job)
schedule.every().minute.at(":17").do(job)

while True:
    schedule.run_pending()
    time.sleep(1)
Related