Skip to content Skip to sidebar Skip to footer

Schedule Python Clear Jobs Queue

I’m a trying to use schedule as follows: def job(): my code schedule.every().day.at('06:03').do(job) schedule.every().day.at('09:56').do(job) while True: schedule.run_pen

Solution 1:

Here an example of a barebone solution for what you need, I try not to optimize to be clear.

It Is a job that just before the end reschedules itself and clears the existing instance.

import time
import schedule

defjob_every_nsec(seconds=10):
    ### Job codeprint("before_job_every_nsec", time.time()) 
    time.sleep(20) 
    print("after_job_every_nsec", time.time())
    ### End of job code # after the code of your job schedule the same job again# notice that the functions calls itself (recursion)
    schedule.every(seconds).seconds.do(job_every_nsec, seconds=seconds)
    # and clear the existing onereturn schedule.CancelJob

defjob_at(start_at):
    ### Job codeprint("before job_at", time.time()) 
    time.sleep(20) 
    print("after job_at", time.time())
    ### End of job code # after the code of your job schedule the same job again
    schedule.every().day.at(start_at)
    # and clear the existing onereturn schedule.CancelJob


# launch jobs for the first time
schedule.every(10).seconds.do(job_every_nsec, seconds=10)
schedule.every().day.at("12:30").do(job_at, start_at="12:30")

whileTrue:
    schedule.run_pending()
    time.sleep(1)

Post a Comment for "Schedule Python Clear Jobs Queue"