On this page
time.monotonic
Prev: time.mktime | Up: time | Next: time.monotonic_ns
Rel: time.asctime, time.clock_getres, time.clock_gettime, time.clock_gettime_ns
Ref: docs.python.org — time.monotonic
Tags: #public #python3 #stdlib #time
Import
import time
from time import monotonic
Signature & Overview
time.monotonic()
Monotonic clock, cannot go backward.
Usage
import time
start = time.monotonic()
time.sleep(0.005)
elapsed = time.monotonic() - start
assert elapsed >= 0.0
Gotchas
- Cannot go backward: Immune to NTP/system clock jumps—always use
monotonic()(orperf_counter()) for timeouts and elapsed durations, nevertime.time(). - Reference point is arbitrary: Only differences (
t2 - t1) are meaningful.
REPL Inspect
from time import monotonic
help(monotonic)
Linked from
Related notes
- tuts/python3/stdlib_module/time/mktime Linked here; links to this page; shared tags: #stdlib, #time
- tuts/python3/stdlib_module/time/monotonic_ns 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