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`.
This commit is contained in:
Marvin Kopf 2025-05-30 08:05:06 +02:00 committed by GitHub
parent f29bcb743b
commit 7a8b4a193f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 2 deletions

View file

@ -230,7 +230,7 @@ KolbyML <https://github.com/KolbyML>
Adnane Taghi <dev@soleuniverse.me> Adnane Taghi <dev@soleuniverse.me>
Spiritual Father <https://github.com/spiritualfather> Spiritual Father <https://github.com/spiritualfather>
Emmanuel Ferdman <https://github.com/emmanuel-ferdman> Emmanuel Ferdman <https://github.com/emmanuel-ferdman>
Marvin Kopf <marvinkopf@outlook.com>
******************** ********************
The text of the 3 clause BSD license follows: The text of the 3 clause BSD license follows:

View file

@ -41,6 +41,7 @@ import time
from queue import Empty, Full, Queue from queue import Empty, Full, Queue
from shutil import which from shutil import which
import aqt
from anki.utils import is_mac, is_win from anki.utils import is_mac, is_win
@ -444,7 +445,7 @@ class MPV(MPVBase):
super().__init__(*args, **kwargs) super().__init__(*args, **kwargs)
self._register_callbacks() aqt.mw.taskman.run_in_background(self._register_callbacks, None)
def _register_callbacks(self): def _register_callbacks(self):
self._callbacks = {} self._callbacks = {}