Skip to content

Commit 1449b99

Browse files
committed
Slightly rephrase to avoid too many is_alive checks
1 parent 73a0f1c commit 1449b99

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/zlib_ng/gzip_ng_threaded.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -362,11 +362,11 @@ def _compress(self, index: int):
362362
in_queue = self.input_queues[index]
363363
out_queue = self.output_queues[index]
364364
compressor: zlib_ng._ParallelCompress = self.compressors[index]
365-
while self._calling_thread.is_alive():
365+
while True:
366366
try:
367367
data, zdict = in_queue.get(timeout=0.05)
368368
except queue.Empty:
369-
if not self.running:
369+
if not (self.running and self._calling_thread.is_alive()):
370370
return
371371
continue
372372
try:
@@ -382,13 +382,13 @@ def _compress(self, index: int):
382382
def _write(self):
383383
index = 0
384384
output_queues = self.output_queues
385-
while self._calling_thread.is_alive():
385+
while True:
386386
out_index = index % self.threads
387387
output_queue = output_queues[out_index]
388388
try:
389389
compressed, crc, data_length = output_queue.get(timeout=0.05)
390390
except queue.Empty:
391-
if not self.running:
391+
if not (self.running and self._calling_thread.is_alive()):
392392
return
393393
continue
394394
self._crc = zlib_ng.crc32_combine(self._crc, crc, data_length)
@@ -402,11 +402,11 @@ def _compress_and_write(self):
402402
raise SystemError("Compress_and_write is for one thread only")
403403
in_queue = self.input_queues[0]
404404
compressor = self.compressors[0]
405-
while self._calling_thread.is_alive():
405+
while True:
406406
try:
407407
data, zdict = in_queue.get(timeout=0.05)
408408
except queue.Empty:
409-
if not self.running:
409+
if not (self.running and self._calling_thread.is_alive()):
410410
return
411411
continue
412412
try:

0 commit comments

Comments
 (0)