Analyzing Python GC output - what is a "cell", and what information is available about it.
Duncan Booth
duncan.booth at invalid.invalid
Fri Jan 11 03:19:36 EST 2008
John Nagle <nagle at animats.com> 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.
>>> def outer():
x = 42
def inner():
return x
return inner
>>> inner = outer()
>>> inner.func_closure[0]
<cell at 0x00C5D450: int object at 0x009657AC>
>>> inner.func_closure[0].cell_contents
42
So in your case, cell.cell_contents.func_name might help.
More information about the Python-list
mailing list