This instance will be upgraded to Heptapod 0.25.0 (final) on 2021-09-22 at 15:00 UTC+2 (a few minutes of down time)

Commit 28ef0db9 authored by Keith Erskine's avatar Keith Erskine
Browse files

fix 1450 file descriptor leak

--HG--
branch : 3.0
parent 5c4a9070abaf
Pipeline #15474 failed with stage
in 5 minutes and 56 seconds
......@@ -105,6 +105,10 @@ def test_file_descriptor_leak(datadir):
num_fds_before = count_open_fds()
wb = load_workbook(filename="sample.xlsx", read_only=True)
# iterate over some but not all rows (#1450)
ws = wb.active
for row in ws.rows:
break
wb.close()
num_fds_after = count_open_fds()
......
......@@ -43,9 +43,11 @@ class ReadOnlyWorksheet(object):
def _get_size(self):
src = self._get_source()
parser = WorkSheetParser(src, [])
dimensions = parser.parse_dimensions()
src.close()
try:
parser = WorkSheetParser(src, [])
dimensions = parser.parse_dimensions()
finally:
src.close()
if dimensions is not None:
self._min_column, self._min_row, self._max_column, self._max_row = dimensions
......@@ -73,29 +75,31 @@ class ReadOnlyWorksheet(object):
counter = min_row
idx = 1
src = self._get_source()
parser = WorkSheetParser(src, self._shared_strings,
data_only=self.parent.data_only, epoch=self.parent.epoch,
date_formats=self.parent._date_formats)
for idx, row in parser.parse():
if max_row is not None and idx > max_row:
break
# some rows are missing
for _ in range(counter, idx):
counter += 1
yield empty_row
# return cells from a row
if counter <= idx:
row = self._get_row(row, min_col, max_col, values_only)
counter += 1
yield row
if max_row is not None and max_row < idx:
for _ in range(counter, max_row+1):
yield empty_row
src.close()
try:
parser = WorkSheetParser(src, self._shared_strings,
data_only=self.parent.data_only,
epoch=self.parent.epoch,
date_formats=self.parent._date_formats)
for idx, row in parser.parse():
if max_row is not None and idx > max_row:
break
# some rows are missing
for _ in range(counter, idx):
counter += 1
yield empty_row
# return cells from a row
if counter <= idx:
row = self._get_row(row, min_col, max_col, values_only)
counter += 1
yield row
if max_row is not None and max_row < idx:
for _ in range(counter, max_row+1):
yield empty_row
finally:
src.close()
def _get_row(self, row, min_col=1, max_col=None, values_only=False):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment