Re: File Closing Problem in 2.3 and 2.4, Not in 2.5



Martin v. Löwis wrote:
Carroll, Barry schrieb:
What I want to know is:

* has anyone else encountered a problem like this, * how was the
problem corrected, * can the fix be retro-fitted to 2.5 and 2.4?

From your description, I suspect an error in your code. Your description
indicates that you don't expect to have more than five files open
simultaneously. Yet, the error message "Too many open files" occurs when
you open many more files (in the order of hundreds of files).

It is very unlikely that there is a bug in Python where it would fail to
close a file when .close() is explicitly invoked on it (as your
description suggests that you do), so if you get that error message, it
can only mean that you fail to close some files.

Notice that you may have other files open, as well, and that those also
count towards the limit.

As a debugging utility, you can use Sysinternal's process explorer.
Make the program halt (not exit) when the exception occurs (e.g. by
having it sleep(1) in a loop), then view all open handles in the
process explorer (check the menu if it doesn't display them initially).

Regards,
Martin

I agree with Martin .. this code to close is solid.

Make certain you are really closing the files when you think you should. I am pretty sure you are not. Look at the code that closes the files closely. Put a print statement in the block that is supposed to close the files (may bee even a raw_input("closing file" + afile) statement).

My guess is that you won't see the print statements trigger when you though they should .. they may be out of "the loop" you thought that they were in.


.



Relevant Pages

  • Re: nesting for statements?
    ... > will only generate the second output "file", (or it's overwriting the ... I think your looping code has the structure ... Inside that loop you want a filename and an integer value in lockstep. ... you have to replace the print statement by your try...except. ...
    (comp.lang.python)
  • Re: Switching with case in perl ?
    ... It would also be better to put that open call prior to the glob. ... You should write it as a regex so people don't misread it: ... the loop", you're doing it at each iteration of the ... aa die statement on each and very print statement which is totally ...
    (comp.lang.perl.misc)
  • Re: Random numer generation without repetition
    ... if I'd use randperm it'll blow my memory ... redo the few that fail. ... loop will essentially never terminate. ...
    (comp.soft-sys.matlab)
  • Re: File Closing Problem in 2.3 and 2.4, Not in 2.5
    ... * can the fix be retro-fitted to 2.5 and 2.4? ... It is very unlikely that there is a bug in Python where it would fail to ... description suggests that you do), so if you get that error message, it ... you can use Sysinternal's process explorer. ...
    (comp.lang.python)
  • Re: Error Message ?
    ... Install SysInternals' Process Explorer. ... Click on it and then click on the window ... displaying the "fAIL" message. ... (default is gray highlighting) ...
    (microsoft.public.windowsxp.general)