Skip to content

Make readme file to be opened using with context#1

Merged
storborg merged 2 commits intostorborg:masterfrom
dahlia:master
Nov 19, 2012
Merged

Make readme file to be opened using with context#1
storborg merged 2 commits intostorborg:masterfrom
dahlia:master

Conversation

@dahlia
Copy link
Copy Markdown
Contributor

@dahlia dahlia commented Nov 19, 2012

The previous example doesn’t explicitly close the opened file object. Although it's almost fine if the interpreter is CPython, but it could be broken if PyPy.

CPython does reference counting instead of garbage collections, and file.__del__() closes the file itself, so files are automatically closed when local scope ends unless these are leaked out of local scope, in CPython.

PyPy does garbage collection so invocation time of __del__() methods cannot be determined. It means files can be unclosed even if local scope ends and these are never leaked out.

If the funniest package in the example are being installed as a dependency of another package by easy_install using PyPy, it may cause “too many open files” error.

How to prevent this problem is to explicitly close() files or to open files using with context (if Python 2.5+).

Many Python packages in PyPI read their readme file to fill long_description in setup.py, but this pattern without explicit closing of file should be discouraged.

The previous example doesn't explicitly close the opened file
object.  Although it's almost fine if the interpreter is CPython
but it could be broken if PyPy.

CPython does reference counting instead of garbage collections,
and file.__del__() closes the file itself, so files are automatically
closed when local scope ends unless these are "leaked" out of local
scope, in CPython.

PyPy does garbage collection so invocation time of __del__() methods
cannot be determined.  It means files can be unclosed even if local
scope ends and these are never leaked out.

If the `funniest` package in the example are being installed as
a dependency of another package by easy_install using PyPy,
it may cause "too many open files" error.

How to prevent this problem is to explicitly close() files or
to open files using with context (if Python 2.5+).

Many python packages in PyPI read their readme file to fill
long_description in setup.py, but this pattern without explicit
closing of file should be discouraged.
storborg added a commit that referenced this pull request Nov 19, 2012
Make readme file to be opened using with context for PyPy's sake
@storborg storborg merged commit e73e0f5 into storborg:master Nov 19, 2012
@storborg
Copy link
Copy Markdown
Owner

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants