[pygtk] File doesn't get closed: how to make sure that the object is 'freed'?

Tim Evans t.evans at aranz.com
Mon Mar 16 08:14:04 WST 2009


Arjen Nienhuis wrote:
> Hi,
> 
> I'm using the glib bindings of poppler through python. Everything works fine:
> 
> - I can open a pdf file
> - I can render it through pycairo
> 
> but after that the file stays open. For each use of
> 'document_new_from_file' one extra file descriptor is used (according
> to lsof). If I leave the program running for a while, I get 'too many
> open files'.
> 
> This is a simple test case that fails after a while:
> 
> =======================================
> 
> import os
> import poppler
> 
> for i in range(1000000):
>     uri = "file://" + os.path.abspath("test.pdf")
>     doc = poppler.document_new_from_file(uri, None)
> 
> =======================================
> 
> Can I check if doc gets freed? Can I force it to free?
> 
> The source code for python-poppler can be found here:
> 
> http://bazaar.launchpad.net/~poppler-python/poppler-python/trunk/files
> 
> I didn't write the wrapper, but if someone can help me fixing it I
> would be very happy!

Try running:

     import gc
     gc.collect()

after you've removed all references to "doc".

-- 
Tim Evans
Applied Research Associates NZ
http://www.aranz.com/


More information about the pygtk mailing list