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
-
Does this answer you question? stackoverflow.com/questions/377454/…Rustam Garayev– Rustam Garayev2021-02-18 07:45:01 +00:00Commented Feb 18, 2021 at 7: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– Geeeeee2021-02-18 07:51:40 +00:00Commented Feb 18, 2021 at 7:51
-
1Does this answer your question? Scheduling tasks using Python's Schedule module. See also Schedule a repeating event in Python 3trincot– trincot2021-02-18 08:11:30 +00:00Commented Feb 18, 2021 at 8:11
-
1Does this answer your question? Schedule a repeating event in Python 3FObersteiner– FObersteiner2021-02-18 08:22:14 +00:00Commented Feb 18, 2021 at 8:22
Add a comment
|
1 Answer
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.sleepallows you to pause your program for a given number of second (say 60 to make 1 minute)while Trueallows 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.
3 Comments
FObersteiner
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
qmeeus
@MrFuppes true that
Geeeeee
Thanks, everyone, that exactly what I wanted to do.