Python - Wait for a specified time (sleep / wait)

To stop a program (thread) for a specified time, use the sleep function of the time module.

To pause a program (thread)

import time

time.sleep(<number of seconds you want to stop the programme>)

Example program

The example program stops for 1.5 seconds using the time.sleep function and displays the elapsed time. The time.time function used in the example program is a function that returns the elapsed seconds since 1 January 1970, called epoch seconds (UNIX time). This is used to measure the execution time of the sleep function.
import time

# Get epoch seconds (UNIX time) before sleep
startSec = time.time()

# Stop for 1.5 seconds

# Calculate and display how long it has been asleep
print(time.time() - startSec)

Result of execution time.sleep


Test Environment