summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKacper Michajłow <kasper93@gmail.com>2025-01-31 06:34:11 +0100
committerKacper Michajłow <kasper93@gmail.com>2025-02-05 20:22:01 +0100
commit62847c9f39c1068944d9e2c62d1687c6f4216327 (patch)
tree8b84a47cc3a4caa5f34fdadab6c6588edd55b77e
parent7372bc5f12952c210ec05e4865e8a2ebd7047892 (diff)
downloadmpv-62847c9f39c1068944d9e2c62d1687c6f4216327.tar.bz2
mpv-62847c9f39c1068944d9e2c62d1687c6f4216327.tar.xz
TOOLS/umpv: handle the case when mpv disappears during adding files
-rwxr-xr-xTOOLS/umpv13
1 files changed, 8 insertions, 5 deletions
diff --git a/TOOLS/umpv b/TOOLS/umpv
index 51e2913230..39fce22269 100755
--- a/TOOLS/umpv
+++ b/TOOLS/umpv
@@ -60,11 +60,14 @@ def get_socket_path() -> str:
return os.path.join(base_dir, ".umpv_socket")
def send_files_to_mpv(sock: socket.socket, files: Iterable[str]) -> None:
- # Unhandled race condition: what if mpv is terminating right now?
- for f in files:
- # escape: \ \n "
- f = f.replace("\\", "\\\\").replace('"', '\\"').replace("\n", "\\n")
- sock.send(f'raw loadfile "{f}" append\n'.encode())
+ try:
+ for f in files:
+ # escape: \ \n "
+ f = f.replace("\\", "\\\\").replace('"', '\\"').replace("\n", "\\n")
+ sock.send(f'raw loadfile "{f}" append\n'.encode())
+ except Exception:
+ print("mpv is terminating or the connection was lost.", file=sys.stderr)
+ sys.exit(1)
def start_mpv(files: Iterable[str], socket_path: str) -> None:
mpv_command = shlex.split(os.getenv("MPV", "mpv"))