Skip to content

Commit e75a63f

Browse files
committed
Fix threaded reader not closing
1 parent 4655b0c commit e75a63f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/isal/igzip_threaded.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ def __init__(self, fp, queue_size=4, block_size=8 * 1024 * 1024):
8383
self.buffer = io.BytesIO()
8484
self.block_size = block_size
8585
self.worker = threading.Thread(target=self._decompress)
86+
self._closed = False
8687
self.running = True
8788
self.worker.start()
8889

@@ -105,6 +106,8 @@ def _decompress(self):
105106
pass
106107

107108
def readinto(self, b):
109+
if self._closed:
110+
raise ValueError("I/O operation on closed file")
108111
result = self.buffer.readinto(b)
109112
if result == 0:
110113
while True:
@@ -129,12 +132,19 @@ def writable(self) -> bool:
129132
return False
130133

131134
def tell(self) -> int:
135+
if self._closed:
136+
raise ValueError("I/O operation on closed file")
132137
return self.pos
133138

134139
def close(self) -> None:
135140
self.running = False
136141
self.worker.join()
137142
self.fileobj.close()
143+
self._closed = True
144+
145+
@property
146+
def closed(self) -> bool:
147+
return self._closed
138148

139149

140150
class _ThreadedGzipWriter(io.RawIOBase):

0 commit comments

Comments
 (0)