restart mpv if it stops responding

https://anki.tenderapp.com/discussions/ankidesktop/31433-error
This commit is contained in:
Damien Elmes 2018-12-13 21:30:17 +10:00
parent 15721d840f
commit 727570418c

View file

@ -344,7 +344,7 @@ class MPVBase:
except Empty: except Empty:
return None 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. """Send a command to the mpv process and collect the result.
""" """
self.ensure_running() self.ensure_running()
@ -353,6 +353,13 @@ class MPVBase:
return self._get_response(timeout) return self._get_response(timeout)
except MPVCommandError as e: except MPVCommandError as e:
raise MPVCommandError("%r: %s" % (message["command"], 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 # Public API