From 727570418ccc5b8324a37b5ead229c1d293045a5 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Thu, 13 Dec 2018 21:30:17 +1000 Subject: [PATCH] restart mpv if it stops responding https://anki.tenderapp.com/discussions/ankidesktop/31433-error --- anki/mpv.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/anki/mpv.py b/anki/mpv.py index 5807d2dbe..93137386f 100644 --- a/anki/mpv.py +++ b/anki/mpv.py @@ -344,7 +344,7 @@ class MPVBase: except Empty: return None - def _send_request(self, message, timeout=None): + def _send_request(self, message, timeout=None, _retry=1): """Send a command to the mpv process and collect the result. """ self.ensure_running() @@ -353,6 +353,13 @@ class MPVBase: return self._get_response(timeout) except MPVCommandError as e: raise MPVCommandError("%r: %s" % (message["command"], e)) + except MPVTimeoutError as e: + if _retry: + print("mpv timed out, restarting") + self._stop_process() + return self._send_request(message, timeout, _retry-1) + else: + raise # # Public API