Probable workaround for mpv failing after a few days on macOS

Also fix the certifi bumper: it was supposed to repeat
This commit is contained in:
Damien Elmes 2022-12-03 22:11:39 +10:00
parent 1a444f30e9
commit fa4fc3e15a
2 changed files with 22 additions and 4 deletions

View file

@ -1382,7 +1382,14 @@ title="{}" {}>{}</button>""".format(
True,
parent=self,
)
self.progress.timer(12 * 60 * 1000, self.refresh_certs, False, parent=self)
if not is_win:
self.progress.timer(
12 * 60 * 1000,
self.temp_file_workarounds,
repeat=True,
requiresCollection=False,
parent=self,
)
def onRefreshTimer(self) -> None:
if self.state == "deckBrowser":
@ -1398,15 +1405,20 @@ title="{}" {}>{}</button>""".format(
if elap > minutes * 60:
self.maybe_auto_sync_media()
def refresh_certs(self) -> None:
def temp_file_workarounds(self) -> None:
import certifi
from aqt.sound import mpvManager
# The requests library copies the certs into a temporary folder on startup,
# and chokes when the file is later missing due to temp file cleaners.
# Work around the issue by accessing them once every 12 hours.
import certifi
with open(certifi.where(), "rb") as f:
f.read()
# Prevent the mpv socket from being removed
mpvManager.bump_socket_mtime()
# Backups
##########################################################################

View file

@ -404,6 +404,12 @@ class MpvManager(MPV, SoundOrVideoPlayer):
self.default_argv += [f"--config-dir={base_path}"]
super().__init__(window_id=None, debug=False)
def bump_socket_mtime(self) -> None:
"Update mtime on socket to prevent temp file cleaners from removing it."
path = Path(self._sock_filename)
if path.exists():
os.utime(path, None)
def on_init(self) -> None:
# if mpv dies and is restarted, tell Anki the
# current file is done