Skip to content

fix: remove duplicate output_fp.close() causing ValueError#78

Open
haosenwang1018 wants to merge 1 commit intoHKUDS:mainfrom
haosenwang1018:fix/eval-double-close-fd-leak
Open

fix: remove duplicate output_fp.close() causing ValueError#78
haosenwang1018 wants to merge 1 commit intoHKUDS:mainfrom
haosenwang1018:fix/eval-double-close-fd-leak

Conversation

@haosenwang1018
Copy link
Copy Markdown

Problem

In evaluation/utils.py, the file handle output_fp is opened at line 153 and properly closed in the finally block. However, there's a second output_fp.close() call immediately after the try/finally block (line 266).

Since the finally block always executes, the second close() call operates on an already-closed file, raising:

ValueError: I/O operation on closed file.

Fix

Remove the redundant output_fp.close() call outside the try/finally block. The finally block already guarantees cleanup.

Testing

Verified the control flow: finally runs in all cases (normal completion, KeyboardInterrupt, any exception), so the second close() is unreachable without the file already being closed.

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.
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.

1 participant