Reputation: 2356
Is there any way to trace life cycle of objects during python code running? I know about sys.settrace function for setting callback, I can stop on each function call or line of code, but how can I get access to "living" objects during this? I would like to trace program so that I can do random checks after each stop, as if I really added code at stop place in sources.
Upvotes: 2
Views: 2218
Reputation: 121
Up to some extend can be done by gc (garbage collector) module in CPython.
Garbage Collector There are few functions using object as parameter and can provide some information regarding object existence:
gc.get_referrers(*objs)
gc.get_referents(*objs)
gc.is_tracked(obj)
To simply check if object exists use 'try' as described here
Upvotes: 2