From 4512cba6290e73e7b7fe8303d6fb448c483476d4 Mon Sep 17 00:00:00 2001 From: pax Date: Sun, 5 Apr 2026 16:26:29 -0500 Subject: [PATCH] =?UTF-8?q?Priority=20downloads=20=E2=80=94=20clicked=20po?= =?UTF-8?q?st=20pauses=20prefetch?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When a post is activated, prefetch pauses via asyncio.Event. The clicked post downloads at full speed without competing. Prefetch resumes after the download completes. --- booru_viewer/gui/app.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/booru_viewer/gui/app.py b/booru_viewer/gui/app.py index ac21813..14c56f9 100644 --- a/booru_viewer/gui/app.py +++ b/booru_viewer/gui/app.py @@ -219,6 +219,8 @@ class BooruApp(QMainWindow): self._min_score = 0 self._loading = False self._last_scroll_page = 0 + self._prefetch_pause = asyncio.Event() + self._prefetch_pause.set() # not paused self._signals = AsyncSignals() self._async_loop = asyncio.new_event_loop() @@ -932,6 +934,7 @@ class BooruApp(QMainWindow): self._signals.download_progress.emit(downloaded, total) async def _load(): + self._prefetch_pause.clear() # pause prefetch try: path = await download_image(post.file_url, progress_callback=_progress) info = f"#{post.id} {post.width}x{post.height} score:{post.score} [{post.rating}] {Path(post.file_url.split('?')[0]).suffix.lstrip('.').upper() if post.file_url else ''}" @@ -939,6 +942,8 @@ class BooruApp(QMainWindow): except Exception as e: log.error(f"Image download failed: {e}") self._signals.image_error.emit(str(e)) + finally: + self._prefetch_pause.set() # resume prefetch self._run_async(_load) @@ -977,6 +982,7 @@ class BooruApp(QMainWindow): async def _prefetch_spiral(): for adj in order: + await self._prefetch_pause.wait() # yield to active downloads if 0 <= adj < len(self._posts) and self._posts[adj].file_url: self._signals.prefetch_progress.emit(adj, 0.0) try: