boto/boto — pull request #1014 by dahlia (2012-09-25 03:06:28+00:00)
Title: Close opened file

While `file.__del__()` closes itself in CPython, PyPy doesn’t use reference counting but garbage collection, so destructors aren’t automatically closed immediately. Invoked time of `__del__` is not decidable in PyPy.

Theoretically it must never cause any problem, but in real world we can’t assume setup.py script is immediately terminated. Because in many cases users install boto using setuptools/`easy_install`. It might cause “too many open files” error. In Windows opened files aren’t accessible by other process. (setuptools tries copying files including `README.rst` while the file has been opened.)

So we should explicitly call `file.close()` in `try`–`finally` block or use `with` block. This patch uses the latter way.