473,473 Members | 1,873 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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

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?

(I'm looking for a possible memory leak, obviously.)

John Nagle
Jan 11 '08 #1
4 2841
John Nagle <na***@animats.comwrote:
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.
Jan 11 '08 #2
Duncan Booth wrote:
John Nagle <na***@animats.comwrote:
>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)
try:
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.

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

Tried:
print item.__dict__
got:
'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
Jan 11 '08 #3
On Jan 11, 2008 6:20 PM, John Nagle <na***@animats.comwrote:
Tried:
print item.dir()
got:
'cell' object has no attribute 'dir'
I don't know nothing about cell objects...
but why don't you try dir(item) instead?

Francesco
Jan 11 '08 #4
Francesco Guerrieri wrote:
On Jan 11, 2008 6:20 PM, John Nagle <na***@animats.comwrote:
>Tried:
print item.dir()
got:
'cell' object has no attribute 'dir'
It's a problem inside MySQLdb's "connections.py":

def _get_unicode_literal():
def unicode_literal(u, dummy=None):
return db.literal(u.encode(unicode_literal.charset))
return unicode_literal

Each time a MySQLdb Connection object is created, it generates a closure,
with another instance of the function "unicode_literal" plus some other
junk. That generates circular references. Eventually those
things get garbage-collected, but if you're running GC in leak detection
mode, they show up.

The reason for the closure is that "unicode_literal.charset" of the
function is being stored into from outside the function. So there
actually is a reason to use a closure.

John Nagle
Jan 11 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Allison Bailey | last post by:
Hi Folks, I'm a brand new Python programmer, so please point me in the right direction if this is not the best forum for this question.... I would like to open an existing MS Excel spreadsheet...
0
by: Carlos Eduardo Peralta | last post by:
Hello dotnet frineds: I make a decision in the 2001 year: i want to be a dotnet guru. I want to consume all my learning hours just learning this applications plataforms and NOT THE JAVA ONE. ...
267
by: Xah Lee | last post by:
Python, Lambda, and Guido van Rossum Xah Lee, 2006-05-05 In this post, i'd like to deconstruct one of Guido's recent blog about lambda in Python. In Guido's blog written in 2006-02-10 at...
1
by: tkpmep | last post by:
I write data to Excel files using PyExcelerator 0.6.3.a and have done so successfully for small files (10-15 cells). I'm experiencing an error when writing a big chunk of data (10,000 cells) to...
4
by: jmbn2k | last post by:
Hi... Iam a fresher from 2006 pass out.This was an interview question asked by a company for which am supposed to giv the answers as soon as possible within Monday..... The problem...
1
by: brixton | last post by:
Hello, probably a simple problem but I can't find how to solve it so here we go... Instead of using a table I'm using lists and CSS for my layout. How do I set the "width" for my list item...
0
by: ehcy | last post by:
anyone plz help me.. i have here a simple program and i want to create an table cell.. what can i do?.. i will show you all my php code.. <?php $fc = "Check.txt"; $handle = fopen($fc,"r");...
17
by: David C. Ullrich | last post by:
Having a hard time phrasing this in the form of a question... The other day I saw a thread where someone asked about overrideable properties and nobody offered the advice that properties are...
0
by: Rich P | last post by:
you could establish a formula where you count the number of characters being displayed when the column width is 50 and then how many chars are displayed with the width is 60, 70, ... Then if the...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.