File Closing Problem in 2.3 and 2.4, Not in 2.5

"Martin v. Löwis" martin at v.loewis.de
Fri Jan 5 22:26:58 EST 2007


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



More information about the Python-list mailing list