How to run a code after every 5 minutes from a specific time from 9:15 am to 3:30 pm?

Viewed 1183

I want to run a script at every 5 minutes but for the time when I run it, I want it to wait for divisible 5 minutes. For ex - current time is 11:32:15 am, so for the first time I would like it to run from 11:35 and then after every 5 minutes till 3:15 pm

1 Answers

You can use the schedule package, it is flexible for this kind of task.

import schedule
import time

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

schedule.every(5).minute.until("2030-01-01 03:15").do(job)

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