all Python 3timefunction
time.sleep()
waiting
Suspends the current thread for the given number of seconds; a fraction such as 0.5 is allowed.
Syntax
time.sleep(seconds)
The pause blocks the whole thread: inside an async function time.sleep() stalls the event loop and every task, use await asyncio.sleep() there. The argument is seconds, not milliseconds: sleep(500) is more than eight minutes. Sleep can last longer than requested (OS scheduling), but since 3.5 not shorter unless a signal handler raises; Ctrl+C interrupts it with KeyboardInterrupt. A negative value raises ValueError.
Examples
import time
t0 = time.monotonic()
time.sleep(0.05)
print(time.monotonic() - t0 >= 0.05) # → True
import time
try:
time.sleep(-1)
except ValueError as e:
print(e) # → sleep length must be non-negative
See also
Common errors
Open in the full glossarydocs.python.orgReport an inaccuracy