-2

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?

Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
Barba
  • 3
  • 1
  • 4
    Hi ! Can you edit your response to show some code you might have come up with ? – ygorg Feb 15 '21 at 13:08
  • 1
    Also see https://stackoverflow.com/a/7370824/14476967 – ygorg Feb 15 '21 at 13:09
  • 2
    Does 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 Answers1

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