Python 3.4+tracemallocfunction
tracemalloc.is_tracing()
tracing control
Returns True if tracemalloc is currently tracing memory allocations.
Syntax
tracemalloc.is_tracing() -> bool
Useful in library code that must neither switch tracing on itself nor break without it: take_snapshot() raises RuntimeError when tracing is off, while get_traced_memory() silently returns (0, 0) — zeros that are easy to read as "memory did not grow". Checking is_tracing() tells "zero" apart from "not measured".
Examples
import tracemalloc
print(tracemalloc.is_tracing()) # → False
print(tracemalloc.get_traced_memory()) # → (0, 0) — не замер, а «не мерили»
tracemalloc.start()
print(tracemalloc.is_tracing()) # → True
tracemalloc.stop()
See also
Open in the full glossarydocs.python.orgReport an inaccuracy