mirror of
https://github.com/ankitects/anki.git
synced 2025-09-24 16:56:36 -04:00
probable fix for win32 startup errors; add timeout to mpv start
This commit is contained in:
parent
1defd698da
commit
519187e941
1 changed files with 20 additions and 11 deletions
31
anki/mpv.py
31
anki/mpv.py
|
@ -138,26 +138,35 @@ class MPVBase:
|
||||||
"""Wait for the mpv process to create the unix socket and finish
|
"""Wait for the mpv process to create the unix socket and finish
|
||||||
startup.
|
startup.
|
||||||
"""
|
"""
|
||||||
# FIXME timeout to give up
|
start = time.time()
|
||||||
while self.is_running():
|
while self.is_running() and time.time() < start+10:
|
||||||
time.sleep(0.1)
|
time.sleep(0.1)
|
||||||
|
|
||||||
try:
|
if isWin:
|
||||||
if isWin:
|
# named pipe
|
||||||
|
try:
|
||||||
self._sock = win32file.CreateFile(r'\\.\pipe\ankimpv',
|
self._sock = win32file.CreateFile(r'\\.\pipe\ankimpv',
|
||||||
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
|
win32file.GENERIC_READ | win32file.GENERIC_WRITE,
|
||||||
0, None, win32file.OPEN_EXISTING, 0, None)
|
0, None, win32file.OPEN_EXISTING, 0, None)
|
||||||
win32pipe.SetNamedPipeHandleState(self._sock,
|
win32pipe.SetNamedPipeHandleState(self._sock,
|
||||||
1, # PIPE_NOWAIT
|
1, # PIPE_NOWAIT
|
||||||
None, None)
|
None, None)
|
||||||
|
except pywintypes.error as err:
|
||||||
|
if err.args[0] == winerror.ERROR_FILE_NOT_FOUND:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
break
|
||||||
else:
|
else:
|
||||||
|
break
|
||||||
|
else:
|
||||||
|
# unix socket
|
||||||
|
try:
|
||||||
self._sock = socket.socket(socket.AF_UNIX)
|
self._sock = socket.socket(socket.AF_UNIX)
|
||||||
self._sock.connect(self._sock_filename)
|
self._sock.connect(self._sock_filename)
|
||||||
except (FileNotFoundError, ConnectionRefusedError):
|
except (FileNotFoundError, ConnectionRefusedError):
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
break
|
break
|
||||||
|
|
||||||
else:
|
else:
|
||||||
raise MPVProcessError("unable to start process")
|
raise MPVProcessError("unable to start process")
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue