I'm trying to make a program with a cycle that ends as soon as sixty seconds have passed but I don't have the slightest idea of how to do so, any ideas?
Asked
Active
Viewed 147 times
-2
-
4Hi ! Can you edit your response to show some code you might have come up with ? – ygorg Feb 15 '21 at 13:08
-
1Also see https://stackoverflow.com/a/7370824/14476967 – ygorg Feb 15 '21 at 13:09
-
2Does this answer your question? [Non-polling/Non-blocking Timer?](https://stackoverflow.com/questions/22180915/non-polling-non-blocking-timer) – Tomerikoo Feb 15 '21 at 13:12
1 Answers
1
You can use the time module to get the system time before the execution of the loop, and then make the loop condition so that it stops when 60 seconds have passed.
import time
seconds = 60
start_time = time.time()
while (time.time() - start_time) < seconds:
print("hello !")

TheEagle
- 5,808
- 3
- 11
- 39