2

I am using python 3.6 & schedule module and needs to schedule a task to run every minute between two time intervals for some specific days of week. For instance, say task is meant to be scheduled for every minute for 2.5 hours time interval of 11:00 PM to 01:30 AM for every Wednesday and Friday. It should be run for every minute between two given time intervals, it should be stopped!

What I have tried:

  1. I tried using schedule.every(1).minutes.do(job) inside schedule.every().day.at("11:00").do(job)

  2. I have built logic to successfully select days of my choice and they can be made available to schedule logic.

But,

  1. That does not stops at specified time and I could not get how to introduce end time limit.

  2. I could not get how to schedule it for 11:00 PM to 01:30 AM, I could not get how to tell it that 01:30 AM comes after 11:00 PM in night.

  3. I do not have any idea about how to schedule it for the days of my choice.

Any help?

Hamza
  • 5,373
  • 3
  • 28
  • 43

2 Answers2

1

I agree with Henry James's answer. It would be better to use cron for tasks like this. I think that cron comes installed by default on unix/linux.

However, if you have to stick to python then you can use

import time
current_time=time.time()

This will give you the current unix time which you can then convert to an hour-min-second format. You will need to run this in a loop to keep checking the time

csoham
  • 140
  • 7
0

If using windows you could use Task scheduler or if UNIX/Linux could use Cron?

That way your script will run and then end, the schedule module looks like it relies on a continuous running of the script.

Henry James
  • 143
  • 3
  • 14