Message126137
> 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:06 | pitrou | set | recipients:
+ pitrou, georg.brandl, ned.deily, pjcreath |
2011-01-12 21:05:05 | pitrou | set | messageid: <1294866305.99.0.882142664623.issue10855@psf.upfronthosting.co.za> |
2011-01-12 21:05:01 | pitrou | link | issue10855 messages |
2011-01-12 21:05:01 | pitrou | create | |
|