trace_object_references¶
- lsst.utils.introspection.trace_object_references(target_class: type, count: int = 5, max_level: int = 10) tuple[list[list], bool] ¶
Find the chain(s) of references that make(s) objects of a class reachable.
- Parameters:
- target_class
type
The class whose objects need to be traced. This is typically a class that is known to be leaking.
- count
int
, optional The number of example objects to trace, if that many exist.
- max_level
int
, optional The number of levels of references to trace.
max_level=1
means finding only objects that directly refer to the examples.
- target_class
- Returns:
- traces
list
[list
] A sequence whose first element (index 0) is the set of example objects of type
target_class
, whose second element (index 1) is the set of objects that refer to the examples, and so on. Contains at mostmax_level + 1
elements.- trace_complete
bool
True
if the trace for all objects terminated in at mostmax_level
references, andFalse
if more references exist.
- traces
Examples
An example with two levels of references:
>>> from collections import namedtuple >>> class Foo: ... pass >>> holder = namedtuple("Holder", ["bar", "baz"]) >>> myholder = holder(bar={"object": Foo()}, baz=42) >>> # In doctest, the trace extends up to the whole global dict >>> # if you let it. >>> trace_object_references(Foo, max_level=2) ... ([[<lsst.utils.introspection.Foo object at ...>], [{'object': <lsst.utils.introspection.Foo object at ...>}], [Holder(bar={'object': <lsst.utils.introspection.Foo object at ...>}, baz=42)]], False)