fix(#328): close file handle in readDataFile using context manager#377
Open
Anirudh77715 wants to merge 1 commit intoEAPD-DRB:mainfrom
Open
fix(#328): close file handle in readDataFile using context manager#377Anirudh77715 wants to merge 1 commit intoEAPD-DRB:mainfrom
Anirudh77715 wants to merge 1 commit intoEAPD-DRB:mainfrom
Conversation
…nager readDataFile used f.close without parentheses, meaning the file descriptor was never actually closed. Replaced with a 'with open()' context manager that guarantees automatic closure.
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.
readDataFile used f.close without parentheses, meaning the file descriptor was never actually closed. Replaced with a
with open()context manager that guarantees automatic closure.Linked issue
Existing related work reviewed
Overlap assessment
Why this PR should proceed
Issue #328 documents a confirmed bug where
f.close(without parentheses) is a no-op, causing file descriptor leaks under repeated calls. This PR applies the standard Python fix using awithcontext manager.Summary
f.closewithwith open() as f:context manager inreadDataFile(API/Classes/Case/DataFileClass.py)f.closewithout()is a no-op — the file is never closed, leaking OS file handles under repeated callsValidation
Documentation
Scope check
OSeMOSYS/MUIOdependencyEAPD-DRB/MUIOGO:main(not upstream)Exception rationale