Skip to content
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

Fix file handling to prevent ValueError #1001

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

TeachMeTW
Copy link
Contributor

@TeachMeTW TeachMeTW commented Dec 16, 2024

Summary

This PR resolves an issue where improper file handling caused the following error:
ValueError: I/O operation on closed file
when running runAllTests.sh

The error occurred because the code attempted to read from a file after it had already been closed. The issue was present both in the original code, which didn’t explicitly close the file, and in a later version where a redundant file read was placed after the file had been closed by a with statement.

Changes Made

  • Updated file handling to use with statements for proper resource management and automatic file closing.
  • Removed redundant query_string = "".join(query_file.readlines()) line that attempted to read the file after it had been closed.
  • Ensured query_string is fully assigned within the scope of the with block.

Impact

  • Fixes ValueError: I/O operation on closed file.

How to Test

  1. Run the script that previously caused the terminal to crash.
  2. Verify that there are no ValueError exceptions in the logs.

Affected #993

- Replaced manual file open/close with `with` statement to ensure proper resource management.
- Removed redundant file read operation after the file was closed.
- Resolved `ValueError: I/O operation on closed file` and addressed terminal crashing issue during execution.
@TeachMeTW TeachMeTW changed the title Fix file handling to prevent ValueError and terminal crashes Fix file handling to prevent ValueError Dec 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: PRs for review by peers
Development

Successfully merging this pull request may close these issues.

1 participant