mirror of
https://github.com/ankitects/anki.git
synced 2025-09-18 22:12:21 -04:00
Fix mpv idle notification not using main thread
Message arrived on a background non-Qt thread, and called run_in_background(), which assumes it's running on the GUI thread. This resulted in single_shot() failing to run in reviewer's on_av_player_did_end_playing on Linux/macOS.
This commit is contained in:
parent
425d9e3fe1
commit
5daafef5e6
2 changed files with 9 additions and 3 deletions
|
@ -442,7 +442,9 @@ class MpvManager(MPV, SoundOrVideoPlayer):
|
||||||
|
|
||||||
def on_property_idle_active(self, value: bool) -> None:
|
def on_property_idle_active(self, value: bool) -> None:
|
||||||
if value and self._on_done:
|
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:
|
def shutdown(self) -> None:
|
||||||
self.close()
|
self.close()
|
||||||
|
|
|
@ -11,7 +11,7 @@ from __future__ import annotations
|
||||||
|
|
||||||
from concurrent.futures import Future
|
from concurrent.futures import Future
|
||||||
from concurrent.futures.thread import ThreadPoolExecutor
|
from concurrent.futures.thread import ThreadPoolExecutor
|
||||||
from threading import Lock
|
from threading import Lock, current_thread, main_thread
|
||||||
from typing import Any, Callable
|
from typing import Any, Callable
|
||||||
|
|
||||||
import aqt
|
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
|
# 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,
|
# 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.
|
# 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:
|
if args is None:
|
||||||
args = {}
|
args = {}
|
||||||
|
|
Loading…
Reference in a new issue