diff --git a/qt/aqt/sound.py b/qt/aqt/sound.py index 1f617e23e..98078cee2 100644 --- a/qt/aqt/sound.py +++ b/qt/aqt/sound.py @@ -442,7 +442,9 @@ class MpvManager(MPV, SoundOrVideoPlayer): def on_property_idle_active(self, value: bool) -> None: if value and self._on_done: - self._on_done() + from aqt import mw + + mw.taskman.run_on_main(self._on_done) def shutdown(self) -> None: self.close() diff --git a/qt/aqt/taskman.py b/qt/aqt/taskman.py index ae5a4d421..0acbcba6c 100644 --- a/qt/aqt/taskman.py +++ b/qt/aqt/taskman.py @@ -11,7 +11,7 @@ from __future__ import annotations from concurrent.futures import Future from concurrent.futures.thread import ThreadPoolExecutor -from threading import Lock +from threading import Lock, current_thread, main_thread from typing import Any, Callable import aqt @@ -65,7 +65,11 @@ class TaskManager(QObject): # to the database that we want to run first - if we delay them until after the # background task starts, and it takes out a long-running lock on the database, # the UI thread will hang until the end of the op. - self._on_closures_pending() + if current_thread() is main_thread(): + self._on_closures_pending() + else: + print("bug: run_in_background not called from main thread") + traceback.print_stack() if args is None: args = {}