请尝试以下操作:
import timetimeout = time.time() + 60*5 # 5 minutes from nowwhile True: test = 0 if test == 5 or time.time() > timeout: break test = test - 1
您可能还想在此处添加短暂睡眠,以使此循环不会占用CPU(例如
time.sleep(1),在循环主体的开头或结尾)。

请尝试以下操作:
import timetimeout = time.time() + 60*5 # 5 minutes from nowwhile True: test = 0 if test == 5 or time.time() > timeout: break test = test - 1
您可能还想在此处添加短暂睡眠,以使此循环不会占用CPU(例如
time.sleep(1),在循环主体的开头或结尾)。