Fix WeFax image not appearing in gallery after stop

stop() was returning before the decode thread could save any partial
image to disk, so the frontend loadImages() call found nothing new.
Join the decode thread (2s timeout) before returning — with select()-
based reads the thread exits within ~0.5s so this stays responsive.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Smittix
2026-02-24 16:16:52 +00:00
parent 9745215038
commit 6894e626a9

View File

@@ -686,19 +686,26 @@ class WeFaxDecoder:
def stop(self) -> None: def stop(self) -> None:
"""Stop WeFax decoder. """Stop WeFax decoder.
Non-blocking: sets _running=False and terminates the process, Sets _running=False and terminates the process outside the lock,
then returns immediately. The decode thread handles cleanup then waits briefly for the decode thread to finish saving any
when its read() returns empty. partial image before returning.
""" """
with self._lock: with self._lock:
self._running = False self._running = False
proc = self._rtl_process proc = self._rtl_process
self._rtl_process = None self._rtl_process = None
thread = self._decode_thread
if proc: if proc:
with contextlib.suppress(Exception): with contextlib.suppress(Exception):
proc.terminate() proc.terminate()
# Wait for the decode thread to save any partial image.
# With select()-based reads the thread exits within ~0.5s.
if thread:
with contextlib.suppress(Exception):
thread.join(timeout=2)
logger.info("WeFax decoder stopped") logger.info("WeFax decoder stopped")
def get_images(self) -> list[WeFaxImage]: def get_images(self) -> list[WeFaxImage]: