is open(...).read() a resource leak?
Fredrik Lundh
fredrik at pythonware.com
Wed Nov 2 13:28:23 EST 2005
Benjamin Rutt wrote:
> If I did the following in an infinite loop, would the host system/user
> account soon run out of file descriptors? (I'm thinking no, since I'd
> imagine that a file object has a __del__-like method that will call
> close() automatically since it goes out of scope):
>
> open('/home/rutt/.bashrc,'r').read()
under CPython, this is not a problem (the reference counting system will
make sure that file handles are reclaimed as fast as new ones are opened).
under an arbitrary Python implementation, it may be a problem, especially
if the implementation doesn't trigger a collection if it runs out of handles (that
can be seen as a bug, though...).
</F>
More information about the Python-list
mailing list