Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion python_mpv_jsonipc.py
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,26 @@ def run(self):
if self.quit_callback:
self.quit_callback()

def _ipc_endpoint_ready(ipc_socket):
"""Return True once MPV's IPC endpoint is available.

On POSIX the endpoint is a filesystem socket, so ``os.path.exists`` works. On
Windows it is a *named pipe*, for which ``os.path.exists`` is always False — so we
probe it with ``WaitNamedPipe`` instead. Using ``os.path.exists`` on Windows made
the startup poll never detect the pipe, raising a spurious "MPV start timed out".
"""
if os.name != 'nt':
return os.path.exists(ipc_socket)
try:
_winapi.WaitNamedPipe(ipc_socket, 0)
return True
except FileNotFoundError:
return False
except OSError:
# Pipe exists but all instances are momentarily busy — it is present.
return True


class MPVProcess:
"""
Manages an MPV process, ensuring the socket or pipe is available. (Internal)
Expand Down Expand Up @@ -248,7 +268,7 @@ def __init__(self, ipc_socket, mpv_location=None, **kwargs):
for _ in range(100): # Give MPV 10 seconds to start.
time.sleep(0.1)
self.process.poll()
if os.path.exists(ipc_socket):
if _ipc_endpoint_ready(ipc_socket):
ipc_exists = True
log.debug("Found MPV socket.")
break
Expand Down