Author lemburg
Recipients alex, amaury.forgeotdarc, benjamin.peterson, brett.cannon, brian.curtin, exarkun, giampaolo.rodola, lemburg, pitrou
Date 2010-10-29.08:07:33
SpamBayes Score 1.03029e-13
Marked as misclassified No
Message-id <4CCA80C3.5080605@egenix.com>
In-reply-to <1287785853.06.0.999498237481.issue10093@psf.upfronthosting.co.za>
Content
Brett Cannon wrote:
> 
> Brett Cannon <brett@python.org> added the comment:
> 
> But this is meant to be an optional warning; users will never see it. Me as a developer, I would like to know when I leave a file open as that is a waste of resources, plus with no guarantee of everything being flushed to disk.

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,
so why should the programmer get warned about this regular
approach to Python programming ?

> Besides, the context manager for files makes the chance of leaving a file open a much more blaring mistake.

See above: context aren't required for working with files. And again:
it's *not* a mistake to not explicitly close a file.

The same applies for sockets.

Think of the simple idiom:

data = open(filename).read()

This would always create a warning under the proposal.

Same for:

for line in open(filename):
   print line

Also note that files and sockets can be kept as references in data
structures (other than local variables or on the stack) and there
you usually have the same approach: you expect Python to close the
files when garbage collecting the data structures and that's
perfectly ok.

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, than scattering warnings around the
application which mostly trigger false positives.
History
Date User Action Args
2010-10-29 08:07:36lemburgsetrecipients: + lemburg, brett.cannon, exarkun, amaury.forgeotdarc, pitrou, giampaolo.rodola, benjamin.peterson, alex, brian.curtin
2010-10-29 08:07:34lemburglinkissue10093 messages
2010-10-29 08:07:33lemburgcreate