Python sys 模块,getobjects() 实例源码

我们从Python开源项目中,提取了以下1个代码示例,用于说明如何使用sys.getobjects()

项目:rdiff-backup    作者:sol1    | 项目源码 | 文件源码
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