Make readme file to be opened using with context#1
Merged
storborg merged 2 commits intostorborg:masterfrom Nov 19, 2012
Merged
Conversation
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
Owner
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The previous example doesn’t explicitly close the opened
fileobject. 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
funniestpackage in the example are being installed as a dependency of another package byeasy_installusing PyPy, it may cause “too many open files” error.How to prevent this problem is to explicitly
close()files or toopenfiles usingwithcontext (if Python 2.5+).Many Python packages in PyPI read their readme file to fill
long_descriptioninsetup.py, but this pattern without explicit closing of file should be discouraged.