Skip to content

Commit 233045f

Browse files
committed
🐛 fix the potential to leave unclosed handle.
1 parent b3cb1a0 commit 233045f

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

pyexcel_io/readers/csv_in_file.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,3 +61,4 @@ def read_sheet(self, index):
6161
def close(self):
6262
for reader in self.handles:
6363
reader.close()
64+
self.handles = []

pyexcel_io/writers/csv_in_file.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,20 @@ def __init__(self, file_alike_object, file_type, **keywords):
1010
if file_type == constants.FILE_FORMAT_TSV:
1111
self._keywords["dialect"] = constants.KEYWORD_TSV_DIALECT
1212
self.__index = 0
13-
self.writer = None
13+
self.handlers = []
1414

1515
def create_sheet(self, name):
16-
self.writer = CSVFileWriter(
16+
writer = CSVFileWriter(
1717
self._file_alike_object,
1818
name,
1919
sheet_index=self.__index,
2020
**self._keywords
2121
)
2222
self.__index = self.__index + 1
23-
return self.writer
23+
self.handlers.append(writer)
24+
return writer
2425

2526
def close(self):
26-
if self.writer:
27-
self.writer.close()
27+
for writer in self.handlers:
28+
writer.close()
29+
self.handlers = []

0 commit comments

Comments
 (0)