How can I run some code, say every 5 minutes, at exact minutes (seconds=0).
I know I can get the time with datetime.datetime.now()
every second and check to see if its minutes is a multiple of 5 and seconds is equal to 0 but isn't there any other way that does not require me to check the time every second?
Asked
Active
Viewed 139 times
-1

Saeed
- 1,848
- 1
- 18
- 26
-
2Consider using [cron](https://en.wikipedia.org/wiki/Cron) – wim Oct 16 '19 at 23:32
-
1You can also get the current time, then time.sleep() till the next multiple of 5 minutes. – jarmod Oct 16 '19 at 23:34
1 Answers
0
I would use datetime like you have to get the difference in time (multiply to get seconds) from now to when you want to run the script and then use time.sleep()
for that number of seconds.
https://www.pythoncentral.io/pythons-time-sleep-pause-wait-sleep-stop-your-code/

Ben Rauzi
- 564
- 4
- 13