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 Crashes and Errors #1000

Closed
wants to merge 11 commits into from
Prev Previous commit
Fix file handling to prevent ValueError and terminal crashes
- 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 committed Dec 16, 2024
commit e7a03ef0a4193d315807d592b88ec9a7423a4086
10 changes: 5 additions & 5 deletions emission/net/ext_service/transit_matching/match_stops.py
Original file line number Diff line number Diff line change
@@ -15,12 +15,12 @@
url = "https://lz4.overpass-api.de/"

try:
query_file = open('conf/net/ext_service/overpass_transit_stops_query_template')
except:
with open('conf/net/ext_service/overpass_transit_stops_query_template', 'r', encoding='UTF-8') as query_file:
query_string = "".join(query_file.readlines())
except FileNotFoundError:
print("transit stops query not configured, falling back to default")
query_file = open('conf/net/ext_service/overpass_transit_stops_query_template.sample')

query_string = "".join(query_file.readlines())
with open('conf/net/ext_service/overpass_transit_stops_query_template.sample', 'r', encoding='UTF-8') as query_file:
query_string = "".join(query_file.readlines())

RETRY = -1

Loading