Skip to content

Fix spurious "MPV start timed out" on Windows (named-pipe readiness check)#23

Open
cognis-digital wants to merge 1 commit into
iwalton3:masterfrom
cognis-digital:fix-windows-pipe-timeout
Open

Fix spurious "MPV start timed out" on Windows (named-pipe readiness check)#23
cognis-digital wants to merge 1 commit into
iwalton3:masterfrom
cognis-digital:fix-windows-pipe-timeout

Conversation

@cognis-digital

Copy link
Copy Markdown

Problem

On Windows, MPV(start_mpv=True, ...) reliably fails with MPVError: MPV start timed out even when MPV launches correctly and the IPC pipe is live.

Root cause

MPVProcess.__init__ polls for the IPC endpoint with:

for _ in range(100):
    time.sleep(0.1)
    if os.path.exists(ipc_socket):   # ipc_socket == r'\.\pipe\<name>' on Windows
        ...

os.path.exists() is always False for Windows named-pipe paths (\.\pipe\...) — os.stat can't stat a pipe — so the loop never detects the pipe and the else branch raises MPV start timed out, despite MPV being up. POSIX is unaffected because there the endpoint really is a filesystem socket.

Fix

Add _ipc_endpoint_ready(): keep os.path.exists on POSIX, but on Windows probe the pipe with _winapi.WaitNamedPipe (the transport layer already depends on _winapi). Minimal, stdlib-only, no new deps, no API change.

Verification

Against MPV v0.41 on Windows 10 / Python 3.14:

  • Before: MPVError: MPV start timed out (every run)
  • After: MPV connects in ~0.5s; idle_active and subsequent commands work.
m = MPV(start_mpv=True, ipc_socket='test', mpv_location=r'...\mpv.exe', vid='no')
# before: raises MPV start timed out
# after:  connects, m.idle_active -> True

MPVProcess polled os.path.exists(ipc_socket) to detect the IPC endpoint
before returning. On Windows the endpoint is a named pipe, and
os.path.exists() is always False for \.\pipe\ paths, so the 10s poll
never detected the pipe and startup raised 'MPV start timed out' even
though MPV was running and the pipe was live.

Probe the pipe with _winapi.WaitNamedPipe on Windows (the transport layer
already uses _winapi); POSIX behavior is unchanged (still os.path.exists).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant