我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用sys.getobjects()。
def getrefs(i, depth): """Get the i'th object in memory, return objects that reference it""" import sys, gc, types o = sys.getobjects(i)[-1] for d in range(depth): for ref in gc.get_referrers(o): if type(ref) in (types.ListType, types.DictType, types.InstanceType): if type(ref) is types.DictType and ref.has_key('copyright'): continue o = ref break else: print "Max depth ", d return o return o