[issue10093] Warn when files are not explicitly closed
report at bugs.python.org
Fri Oct 29 10:22:36 CEST 2010
Antoine Pitrou <pitrou at free.fr> added the comment:
> That's what I'm referring to: most Python applications are
> written with the fact in mind, that garbage collection will
> close the files or socket.
> That's a perfectly fine way of writing Python applications,
Some people would disagree, especially Windows users who cannot timely
delete files when some file descriptors still point to them.
> so why should the programmer get warned about this regular
> approach to Python programming ?
Again: it is an *optional* warning. It is *disabled* by default, except
when compiled --with-pydebug.
> The same applies for sockets.
It is *definitely* a mistake if the socket has been bound to a local
address and/or connected to a remote endpoint.
> Think of the simple idiom:
> data = open(filename).read()
> This would always create a warning under the proposal.
We have had many Windows buildbot failures because of such coding style.
> If you want to monitor resource usage in your application it
> would be a lot more useful to provide access to the number of
> currently open FDs
Agreed it would be useful as well, but please tell that to operating
system vendors. Python has no way to calculate such a statistic.
Python tracker <report at bugs.python.org>
More information about the Python-bugs-list