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

Arjen Nienhuis arjen at bleenterprises.nl
Mon Mar 16 08:37:43 WST 2009


> Try running:
>
>    import gc
>    gc.collect()
>
> after you've removed all references to "doc".

Hi,

Thanks.

I have this now. It still breaks. Only slower. gc.collect() is slow.

===========================

import os
import poppler
import gc

for i in range(1000000):
    print i
    uri = "file://" + os.path.abspath("test.pdf")
    doc = poppler.document_new_from_file(uri, None)
    del doc
    gc.collect()

===========================

Groeten, Arjen

On Mon, Mar 16, 2009 at 12:14 AM, Tim Evans <t.evans at aranz.com> wrote:
> 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!
>


More information about the pygtk mailing list