Answers for "python stop while loop after time"

0

how to end an infinite loop in specific time python

import time

# timeout variable can be omitted, if you use specific value in the while condition
timeout = 300   # [seconds]

timeout_start = time.time()

while time.time() < timeout_start + timeout:
    test = 0
    if test == 5:
        break
    test -= 1
Posted by: Guest on May-14-2020
0

python stop while loop after time

import time
timeout = time.time() + 60*5   # 5 minutes from now
while True:
    test = 0
    if test == 5 or time.time() > timeout:
        break
    test = test - 1
Posted by: Guest on March-19-2021

Python Answers by Framework

Browse Popular Code Answers by Language