python 5 second loop code example Example: how to make a while loop run for 5 seconds import time t_end = time.time() + 60 * 15 while time.time() < t_end: