How to make a time delay in Python or Wait for a time span
0
1397
If you want to put a time delay in a python program, you can use time module as follows
import time
time.sleep(300) # It delays the program for 500 seconds / 5 minutes
If you want to wait for a partulcar time period and do some actions, the following codes can be used
# Run some codes up to 300 seconds
import time
timeout = 300 # wait until 300 seconds
start_time = time.time()
while time.time() - start_time < timeout:
print("Do your stuff...")
# This loop exits exactly after 300 seconds
Comment here