I'd like to use the Schedule library for Python, but I don't quite understand how it works.
def job():
% my program here
schedule.every().day.at("10:30").do(job)
If I run this code once from the terminal, will it always run job
at 10:30 every day? Or do I also need to add something like:
while True:
schedule.run_pending()
time.sleep(1)
(I'm getting all this code from the github for the library)
Or do I need to continuously run the scheduler without blocking the main thread as described in the FAQ for the library?
Does my terminal always need to be open?
Based on the github doc you had linked, as well as the developer interface, you do have to put run_pending()
and some length of sleep
in an infinite loop.
You do not need to run the scheduler from another thread, unless you program does something in the main thread other than scheduling. If you are only using it to schedule, there is no need.
If you close the terminal, the whole program closes, so yes the terminal needs to stay open.