From 7a8b4a193f9dac647208eddc3808fc1985c2a6fc Mon Sep 17 00:00:00 2001 From: Marvin Kopf Date: Fri, 30 May 2025 08:05:06 +0200 Subject: [PATCH] offload mpv callback registration to background thread to avoid UI blocking (#4038) Instantiating `MPV(MPVBase)` triggers multiple synchronous `command()` calls to the mpv process during callback registration. These calls block the main thread and degrade startup performance. This change defers registration via `taskman.run_in_background`. --- CONTRIBUTORS | 2 +- qt/aqt/mpv.py | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CONTRIBUTORS b/CONTRIBUTORS index e8814bf93..068760e6b 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -230,7 +230,7 @@ KolbyML Adnane Taghi Spiritual Father Emmanuel Ferdman - +Marvin Kopf ******************** The text of the 3 clause BSD license follows: diff --git a/qt/aqt/mpv.py b/qt/aqt/mpv.py index 60ea21290..329a95538 100644 --- a/qt/aqt/mpv.py +++ b/qt/aqt/mpv.py @@ -41,6 +41,7 @@ import time from queue import Empty, Full, Queue from shutil import which +import aqt from anki.utils import is_mac, is_win @@ -444,7 +445,7 @@ class MPV(MPVBase): super().__init__(*args, **kwargs) - self._register_callbacks() + aqt.mw.taskman.run_in_background(self._register_callbacks, None) def _register_callbacks(self): self._callbacks = {}