fix: remove duplicate output_fp.close() causing ValueError#78
Open
haosenwang1018 wants to merge 1 commit intoHKUDS:mainfrom
Open
fix: remove duplicate output_fp.close() causing ValueError#78haosenwang1018 wants to merge 1 commit intoHKUDS:mainfrom
haosenwang1018 wants to merge 1 commit intoHKUDS:mainfrom
Conversation
output_fp is opened at line 153 and closed in the finally block (line 261).
However, there is a second output_fp.close() call at line 266 outside the
try/finally, which raises ValueError('I/O operation on closed file') when
execution reaches it after the finally block runs.
Remove the redundant close() call since the finally block already guarantees
proper cleanup.
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.
Problem
In
evaluation/utils.py, the file handleoutput_fpis opened at line 153 and properly closed in thefinallyblock. However, there's a secondoutput_fp.close()call immediately after thetry/finallyblock (line 266).Since the
finallyblock always executes, the secondclose()call operates on an already-closed file, raising:Fix
Remove the redundant
output_fp.close()call outside thetry/finallyblock. Thefinallyblock already guarantees cleanup.Testing
Verified the control flow:
finallyruns in all cases (normal completion,KeyboardInterrupt, any exception), so the secondclose()is unreachable without the file already being closed.