Skip to content

Commit 2c4b4b6

Browse files
committed
feat: fix bug exception unclose
1 parent 8c9b8d0 commit 2c4b4b6

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

dingo/data/datasource/local.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,14 @@ def _load_excel_file_xlsx(self, path: str) -> Generator[str, None, None]:
133133
# 转换为 JSON 字符串并 yield
134134
yield json.dumps(row_dict, ensure_ascii=False) + '\n'
135135

136-
wb.close()
137-
138136
except Exception as e:
139137
raise RuntimeError(
140138
f'Failed to read .xlsx file "{path}": {str(e)}. '
141139
f'Please ensure the file is a valid Excel file (.xlsx).'
142140
)
141+
finally:
142+
if wb:
143+
wb.close()
143144

144145
def _load_excel_file_xls(self, path: str) -> Generator[str, None, None]:
145146
"""
@@ -210,13 +211,14 @@ def _load_excel_file_xls(self, path: str) -> Generator[str, None, None]:
210211
# 转换为 JSON 字符串并 yield
211212
yield json.dumps(row_dict, ensure_ascii=False) + '\n'
212213

213-
wb.release_resources()
214-
215214
except Exception as e:
216215
raise RuntimeError(
217216
f'Failed to read .xls file "{path}": {str(e)}. '
218217
f'Please ensure the file is a valid Excel file (.xls).'
219218
)
219+
finally:
220+
if wb:
221+
wb.release_resources()
220222

221223
def _load_local_file(self) -> Generator[str, None, None]:
222224
"""

0 commit comments

Comments
 (0)