Close opened file in setup.py script #1014

Merged
merged 1 commit into from Oct 14, 2012

2 participants

@dahlia

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.

Ideally 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 tryfinally block or use with block. This patch uses the latter way.

@dahlia dahlia 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
indeterministic 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.

So we should explicitly call file.close() in try-finally block or
use with block.  This patch uses the latter way.
610752d
@garnaat garnaat merged commit 610752d into boto:develop Oct 14, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment