how can I loop print something 5 times every minute like when 09.01 am print something 5 times then do nothing till 09.02 am and print other things 5 times then do nothing
Asked
Active
Viewed 106 times
1
-
Does this answer you question? https://stackoverflow.com/questions/377454/how-do-i-get-my-python-program-to-sleep-for-50-milliseconds – Rustam Garayev Feb 18 '21 at 07:45
-
No, assume I give you to do work at 10.00 when you are done you can take a rest but when 11.00 you will do new work. – Geeeeee Feb 18 '21 at 07:51
-
1Does this answer your question? [Scheduling tasks using Python's Schedule module](https://stackoverflow.com/questions/42444329/scheduling-tasks-using-pythons-schedule-module). See also [Schedule a repeating event in Python 3](https://stackoverflow.com/questions/2398661/schedule-a-repeating-event-in-python-3) – trincot Feb 18 '21 at 08:11
-
1Does this answer your question? [Schedule a repeating event in Python 3](https://stackoverflow.com/questions/2398661/schedule-a-repeating-event-in-python-3) – FObersteiner Feb 18 '21 at 08:22
1 Answers
1
Here are some elements of answer:
datetime.datetime.now()
gives you the time of, well, now. Use it to check whether it's 10 amtime.sleep
allows you to pause your program for a given number of second (say 60 to make 1 minute)while True
allows you to run a program continuously
Also, note that it is probably not the best approach. On linux and mac you have utilities such as cron to do that. Pretty sure something exists on Windows as well. Bottom line: scheduling is best managed by your os, not by a python script.

qmeeus
- 2,341
- 2
- 12
- 21
-
guess you might also want to point to something async; typically you don't want the timer of your scheduled task block all the rest of your code – FObersteiner Feb 18 '21 at 08:23
-
-