Analyzing Python GC output - what is a "cell", and what information is available about it.

John Nagle nagle at
Fri Jan 11 18:20:12 CET 2008

Duncan Booth wrote:
> John Nagle <nagle at> wrote:
>> I'm printing out each entry in "gc.garbage" after a garbage collection in
>> DEBUG_LEAK mode, and I'm seeing many entries like
>> <cell at 0x00F7C170: function object at 0x00FDD6B0>
>> That's the output of "repr".   Are "cell" objects created only from
>> external C libraries, or can regular Python code generate them?  Is there
>> any way to find out what the 'function object' is from within Python?
> Cell objects are created whenever you have a function that references a 
> variable in an outer scope. e.g.
> So in your case, cell.cell_contents.func_name might help.

    Tried that:

			print repr(item).encode('ascii','replace')	
			print "Type:",type(item)
				print item.cell_contents
			except Exception, message:
				print "Unprintable:",message

<cell at 0x00F88DF0: function object at 0x0100CFB0>
Type: <type 'cell'>
Unprintable: 'cell' object has no attribute 'cell_contents'

So it doesn't have a "cell_contents" attribute.

	print item.dir()
	'cell' object has no attribute 'dir'

	print item.__dict__
	'cell' object has no attribute '__dict__'

It looks like this is a low-level PyCellObject not generated from Python code.
Any ideas?  I'm using the M2Crypto and MySQLdb libraries, and suspect
a reference count bug in one of those.

					John Nagle

More information about the Python-list mailing list