Python Forum
How to trigger python script twice a day - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: How to trigger python script twice a day (/thread-20766.html)



How to trigger python script twice a day - SriMekala - Aug-29-2019

Hi,
I want to trigger my python program every day at 8 am & 11 pm. I try to test this using below code, but the program did work well.

import schedule
import time

def job():
    print("I'm working...")
schedule.every().day.at("23:06").do(job)
print('hi at 23:06')
schedule.every().day.at("23:08").do(job)
print('Hi 23:08')
How to trigger at specified times?


RE: How to trigger python script twice a day - scidam - Aug-30-2019

I didn't use schedule module before, but it seems from docs that you need to run it in an infinite loop, i.e. your code should be something like this:

import schedule
import time
 
def job():
    print("I'm working...")
    print("hi at %s" % time.ctime())

schedule.every().day.at("23:06").do(job)
schedule.every().day.at("23:08").do(job)

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