On this page
time.sleep
Prev: time.process_time_ns | Up: time | Next: time.strftime
Rel: time.asctime, time.clock_getres, time.clock_gettime, time.clock_gettime_ns
Ref: docs.python.org — time.sleep
Tags: #public #python3 #stdlib #time
Import
import time
from time import sleep
Signature & Overview
time.sleep(object, /)
Delay execution for a given number of seconds. The argument may be a floating-point number for subsecond precision.
Usage
import time
t0 = time.monotonic()
time.sleep(0.01)
assert time.monotonic() - t0 >= 0.005
Gotchas
- Blocks the entire thread: Never call
time.sleep()insideasync def—useawait asyncio.sleep()instead. - Actual sleep may be slightly longer than requested due to OS scheduler granularity.
REPL Inspect
from time import sleep
help(sleep)
Linked from
Related notes
- tuts/python3/stdlib_module/time/process_time_ns Linked here; links to this page; shared tags: #stdlib, #time
- tuts/python3/stdlib_module/time/strftime Linked here; links to this page; shared tags: #stdlib, #time
- tuts/python3/stdlib_module/time/asctime Linked here; shared tags: #stdlib, #time
- tuts/python3/stdlib_module/time/clock_getres Linked here; shared tags: #stdlib, #time
- tuts/python3/stdlib_module/time/clock_gettime Linked here; shared tags: #stdlib, #time
- tuts/python3/stdlib_module/time/clock_gettime_ns Linked here; shared tags: #stdlib, #time
- tuts/python3/stdlib_module/time/time Linked here; shared tags: #stdlib, #time
- tuts/python3/stdlib_module/time links to this page; shared tags: #stdlib
- tuts/c/stdlib/time shared tags: #stdlib, #time
- tuts/c/stdlib/time/asctime shared tags: #stdlib, #time