This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author lemburg
Recipients alex, amaury.forgeotdarc, benjamin.peterson, brett.cannon, brian.curtin, exarkun, giampaolo.rodola, lemburg, pitrou
Date 2010-10-29.12:55:47
SpamBayes Score 2.0826523e-09
Marked as misclassified No
Message-id <4CCAC451.9030703@egenix.com>
In-reply-to <1288353153.3565.66.camel@localhost.localdomain>
Content
Antoine Pitrou wrote:
> 
> Antoine Pitrou <pitrou@free.fr> added the comment:
> 
>> Whether you write an application with automatic closing of
>> the file/socket at garbage collection time in mind, or you explicitly
>> close the file/socket, the timing is the same.
> 
> No, because objects can be kept alive through tracebacks (or reference
> cycles).

If you get a traceback, the explicitly file.close() won't help
you either; but that usually doesn't matter, since program
execution will stop, the traceback will get GCed and the file
closed. This is a very normal and reasonable expectation of a
Python programmer.

>> I don't follow you. Where's the difference between writing:
>>
>> s.close()
>> or
>> s = None
>>
>> for an open socket s ?
> 
> The difference is when s is still referenced elsewhere.
> Also, the intent of the former is clear while the latter is deliberately
> obscure (while not saving any significant amount of typing).

Sure, but that's not the point. It is not a mistake to write
such code and neither is this obscure, otherwise we'd also
require explicit garbage collection for other parts of Python.

If the application keeps references to the objects in other
places, the programmer would, of course, add an explicit .close().
Ditto for the files.

>> The for-loop file iterator support was explicitly added to make
>> writing:
>>
>> for line in open(filename):
>>     print line
>>
>> possible.
> 
> So what?

The warning will trigger without any reason.

>> At least for Linux, that's not hard and I doubt it is for other OSes.
>>
>> 4
>>
>> On other Unixes, you can simply use fcntl() to scan all possible FDs
>> for open FDs.
>>
>> On Windows you can use one of these functions for the same effect:
>> http://msdn.microsoft.com/en-us/library/kdfaxaay(v=VS.90).aspx
> 
> Until you post some code I won't understand what you are talking about.

RoundUp's email interface ate the code. I'll post it again via the
web interface.
History
Date User Action Args
2010-10-29 12:55:50lemburgsetrecipients: + lemburg, brett.cannon, exarkun, amaury.forgeotdarc, pitrou, giampaolo.rodola, benjamin.peterson, alex, brian.curtin
2010-10-29 12:55:48lemburglinkissue10093 messages
2010-10-29 12:55:47lemburgcreate