Skip to content Skip to sidebar Skip to footer

Executing Function At Specified Time

I want to execute some code at 12 o clock everyday. The only way I can think todo this is to sleep until 12 o clock execute code sleep 24 hours (minus time takes to run code) go

Solution 1:


Solution 2:

Hope this would work for you

import threading
def latercomer():
    print "Oops I am Late"

t = threading.Timer(30.0, latercomer)
t.start()

latecomer will be called after 30 secs


Solution 3:

I think this package will be useful for your case.

pip install schedule

And here is the snippet of the code from the documentation:

import schedule
import time

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

schedule.every(10).minutes.do(job)
schedule.every().hour.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)

Post a Comment for "Executing Function At Specified Time"