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_classtype
- The class whose objects need to be traced. This is typically a class that is known to be leaking. 
- countint, optional
- The number of example objects to trace, if that many exist. 
- max_levelint, optional
- The number of levels of references to trace. - max_level=1means finding only objects that directly refer to the examples.
 
- target_class
- Returns:
- traceslist[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 most- max_level + 1elements.
- trace_completebool
- Trueif the trace for all objects terminated in at most- max_levelreferences, and- Falseif 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)