Skip to content

Enforce correct file closure #63

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2016

Conversation

frasercrossman
Copy link
Contributor

with statement added to ensure file is correctly closed under all circumstances.
Although CPython will garbage collect the file object following the read operation, other implementations of Python may not. The file often is not immediately closed and is left to be disguarded at a later unknown point of execution. Additionally, in Python 3.2 or above the current implementation will throw a ResourceWarning exception which must otherwise be caught if enabled. Better safe than sorry.

Source: StackOverflow

with statement added to ensure file is correctly closed under all circumstances.
Although CPython will garbage collect the file object following the read operation, other implementations of Python may not. The file often is not immediately closed and is left to be disguarded at a later unknown point of execution. Additionally, in Python 3.2 or above the current implementation will throw a ResourceWarning exception which must otherwise be caught if enabled. Better safe than sorry.
@geekcomputers geekcomputers merged commit 9f78b72 into geekcomputers:master Jul 28, 2016
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