File Closing Problem in 2.3 and 2.4, Not in 2.5 (Final report)

Mark T nospam at nospam.com
Tue Jan 9 23:42:48 EST 2007


"Gabriel Genellina" <gagsl-py at yahoo.com.ar> wrote in message 
news:mailman.2505.1168387540.32031.python-list at python.org...
> At Tuesday 9/1/2007 20:31, Carroll, Barry wrote:
>
>>I've spent about a day investigating our "too many open files" error.  I
>>found the following:
>>
>>         1. Windows XP allows a Python 2.5 script to open 509 concurrent
>>            files.
>
> And do you actually need so many open files simultaneously?
> Try to close them explicitely when you finish working on them - do not 
> rely on GC for closing files. This has *always* been the recomended 
> practice (except maybe, inside a short script that finishes quickly).
> On Python 2.5 you can use the new `with` statement.
>
>
> -- 
> Gabriel Genellina
> Softlab SRL

After a quick scan of this thread, I didn't see the actual source for your 
call to the file's close().  Is it perhaps "file.close" and not 
"file.close()"?  Forgotten parentheses won't give an error and won't close 
the file.

>>> f=file('blah.txt','wt')
>>> f
<open file 'blah.txt', mode 'wt' at 0x00ECB9F8>
>>> f.close
<built-in method close of file object at 0x00ECB9F8>
>>> f
<open file 'blah.txt', mode 'wt' at 0x00ECB9F8>
>>> f.close()
>>> f
<closed file 'blah.txt', mode 'wt' at 0x00ECB9F8>
>>>

-Mark Tolonen




More information about the Python-list mailing list