[Tutor] timeout

Hugo González Monteverde hugonz-lists at h-lab.net
Mon Jan 16 18:01:11 CET 2006

Hi Frank,

 > how can I break a loop after a certain amount of time has passed?

If the loop actually does something, I've used time.time() in the past:

start_time = time.time()
timeout = 60 #seconds

while True:
     if time.time() - start_time >= timeout:

time.time() just keeps increasing as it reports the system's clock (in 
UNIX epoch time, just increasing seconds)

Hope that helps,


More information about the Tutor mailing list