Skip to content

Commit

Permalink
Fix file handling to prevent ValueError and terminal crashes
Browse files Browse the repository at this point in the history
- 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.
  • Loading branch information
TeachMeTW committed Dec 16, 2024
1 parent 3d688f2 commit e7a03ef
Showing 1 changed file with 5 additions and 5 deletions.
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
Expand Up @@ -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

Expand Down

0 comments on commit e7a03ef

Please sign in to comment.