Skip to content

Commit a0639b9

Browse files
committed
Prevent threads from blocking python exit
1 parent a1286cf commit a0639b9

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

CHANGELOG.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ Changelog
77
.. This document is user facing. Please word the changes in such a way
88
.. that users understand how the changes affect the new version.
99
10+
version 1.7.1-dev
11+
-----------------
12+
+ Prevent threaded opening from blocking python exit when an error is thrown
13+
in the calling thread.
14+
1015
version 1.7.0
1116
-----------------
1217
+ Include a patched ISA-L version 2.31. The applied patches make compilation

src/isal/igzip_threaded.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def __init__(self, filename, queue_size=2, block_size=1024 * 1024):
101101
self.worker = threading.Thread(target=self._decompress)
102102
self._closed = False
103103
self.running = True
104+
self._calling_thread = threading.current_thread()
104105
self.worker.start()
105106

106107
def _check_closed(self, msg=None):
@@ -110,15 +111,15 @@ def _check_closed(self, msg=None):
110111
def _decompress(self):
111112
block_size = self.block_size
112113
block_queue = self.queue
113-
while self.running:
114+
while self.running and self._calling_thread.is_alive():
114115
try:
115116
data = self.fileobj.read(block_size)
116117
except Exception as e:
117118
self.exception = e
118119
return
119120
if not data:
120121
return
121-
while self.running:
122+
while self.running and self._calling_thread.is_alive():
122123
try:
123124
block_queue.put(data, timeout=0.05)
124125
break
@@ -215,6 +216,7 @@ def __init__(self,
215216
if "b" not in mode:
216217
mode += "b"
217218
self.lock = threading.Lock()
219+
self._calling_thread = threading.current_thread()
218220
self.exception: Optional[Exception] = None
219221
self.level = level
220222
self.previous_block = b""
@@ -348,7 +350,7 @@ def _compress(self, index: int):
348350
try:
349351
data, zdict = in_queue.get(timeout=0.05)
350352
except queue.Empty:
351-
if not self.running:
353+
if not (self.running and self._calling_thread.is_alive()):
352354
return
353355
continue
354356
try:
@@ -373,7 +375,7 @@ def _write(self):
373375
try:
374376
compressed, crc, data_length = output_queue.get(timeout=0.05)
375377
except queue.Empty:
376-
if not self.running:
378+
if not (self.running and self._calling_thread.is_alive()):
377379
self._crc = total_crc
378380
self._size = size
379381
return
@@ -396,7 +398,7 @@ def _compress_and_write(self):
396398
try:
397399
data, zdict = in_queue.get(timeout=0.05)
398400
except queue.Empty:
399-
if not self.running:
401+
if not (self.running and self._calling_thread.is_alive()):
400402
self._crc = total_crc
401403
self._size = size
402404
return

0 commit comments

Comments
 (0)