1import time
2
3# timeout variable can be omitted, if you use specific value in the while condition
4timeout = 300 # [seconds]
5
6timeout_start = time.time()
7
8while time.time() < timeout_start + timeout:
9 test = 0
10 if test == 5:
11 break
12 test -= 1
1import time
2timeout = time.time() + 60*5 # 5 minutes from now
3while True:
4 test = 0
5 if test == 5 or time.time() > timeout:
6 break
7 test = test - 1