Python Glossary Русский

Python 3.4+tracemallocfunction

tracemalloc.get_traceback_limit()

tracing control

Returns how many stack frames tracemalloc stores in each trace (the nframe argument of start()).

Syntax

tracemalloc.get_traceback_limit() -> int

The default limit is 1: you see only the line where the allocation happened, not who called the function. That is not enough to find a leak inside a shared factory function — you need start(10) and statistics('traceback'). The limit is frozen into a snapshot as Snapshot.traceback_limit: a snapshot taken with limit 1 cannot be "deepened" later.

Examples

import tracemalloc
print(tracemalloc.get_traceback_limit())  # → 1
tracemalloc.start(5)
snap = tracemalloc.take_snapshot()
print(tracemalloc.get_traceback_limit(), snap.traceback_limit)  # → 5 5
tracemalloc.stop()

See also

Open in the full glossarydocs.python.orgReport an inaccuracy