Python sys.getobjects() Examples

The following are code examples for showing how to use sys.getobjects(). They are extracted from open source Python projects. You can vote up the examples you like or vote down the ones you don't like. You can also save this page to your account.

Example 1
Project: rdiff-backup   Author: sol1   File: commontest.py    (license) View Source Project 6 votes vote down vote up
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