Author pitrou
Recipients georg.brandl, ned.deily, pitrou, pjcreath
Date 2011-01-12.21:05:01
SpamBayes Score 2.38445e-09
Marked as misclassified No
Message-id <>
> It allows garbage collection to close the file object if there are no 
> more references to it.

This is a very bad policy to begin with. Garbage collection can be delayed for a number of reasons:
- someone might be running your program on a Python implementation which doesn't use reference counting (such as Jython or PyPy)
- an exception, together with its traceback object, might capture the value of some local variables and keep them alive (that is, reachable from the GC's point of view)
- a reference cycle might delay proper resource cleanup until the cyclic garbage collector kicks in

So the good thing to do is to close your file explicitly. Luckily, Python 2.6 and upwards makes it easier by using the "with" statement.

IMO this issue should be closed.
Date User Action Args
2011-01-12 21:05:06pitrousetrecipients: + pitrou, georg.brandl, ned.deily, pjcreath
2011-01-12 21:05:05pitrousetmessageid: <>
2011-01-12 21:05:01pitroulinkissue10855 messages
2011-01-12 21:05:01pitroucreate