📜  如何在特定时间结束无限循环python代码示例

📅  最后修改于: 2022-03-11 14:45:41.309000             🧑  作者: Mango

代码示例1
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