From 388ed0bf9d57451de98ff8d42137105eb1a729a4 Mon Sep 17 00:00:00 2001 From: arabcoders Date: Tue, 24 Jun 2025 17:38:11 +0300 Subject: [PATCH] Handle Download queue task exceptions --- app/library/DownloadQueue.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/app/library/DownloadQueue.py b/app/library/DownloadQueue.py index 2f62cd59..dd92fcf6 100644 --- a/app/library/DownloadQueue.py +++ b/app/library/DownloadQueue.py @@ -720,11 +720,9 @@ class DownloadQueue(metaclass=Singleton): if entry.started() or entry.is_cancelled(): continue - # Bypass semaphore for temporary workers - if entry.is_live: - asyncio.create_task(self._download_temp(_id, entry)) - else: - asyncio.create_task(self._download(_id, entry)) + asyncio.create_task( + self._download_temp(_id, entry) if entry.is_live else self._download(_id, entry) + ).add_done_callback(self._handle_task_exception) await asyncio.sleep(0.5) @@ -894,3 +892,10 @@ class DownloadQueue(metaclass=Singleton): self.done.put(item) LOG.exception(e) LOG.error(f"Failed to retry item '{item_ref}'. {e!s}") + + def _handle_task_exception(self, task: asyncio.Task): + if task.cancelled(): + return + + if exc := task.exception(): + LOG.error(f"Unhandled exception in background task: {exc!s}")