How to start a command at a given time insidea python code? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

How to start a command at a given time insidea python code?

For examle every half an hour...

24th Oct 2021, 6:13 AM
Márton Fiers
Márton Fiers - avatar
5 Answers
+ 2
Use time module
24th Oct 2021, 6:16 AM
Prabhas Koya
+ 1
So make your code to calculate the time taken for every run (your process time) and subtract the time(time.sleep(your subtracted time) to make it exactly half an hour
25th Oct 2021, 3:35 AM
Prabhas Koya
0
Yes, i used it already. Here's my code.(temp read software for rpi): www.fierostudio.hu/10.pdf Now it waits 1800 sec (time.sleep(1800)) after every loop. Because process takes some secs every time, so there will be a little more time between the instructions are done. So i would like to start the instructions inside the loop in every exact half an hour. Is there a simple function for that inside the time module? I hope i was clear. Thanks!
24th Oct 2021, 6:56 PM
Márton Fiers
Márton Fiers - avatar
0
Wow! Thanks! That was the idea i needed!
25th Oct 2021, 6:59 AM
Márton Fiers
Márton Fiers - avatar
0
Because of the troubleshooting process, one run's duration can't be predictible. But at the end of one run, i can get the exact time, and from it i can calculate the upcoming sleep time. So thanks for the idea. Before, i was thinking of how to start a run at a given time... So the code allways would had to watch the time somehow...
25th Oct 2021, 7:04 AM
Márton Fiers
Márton Fiers - avatar