timeout for commands
This commit is contained in:
parent
0085fbc999
commit
41bc93feb9
1 changed files with 10 additions and 7 deletions
17
app.py
17
app.py
|
@ -103,7 +103,7 @@ async def mpv_socket_open() -> tuple[StreamReader, StreamWriter] | None:
|
|||
|
||||
if mpv_running():
|
||||
try:
|
||||
return await asyncio.wait_for(socket_open_helper(), timeout=3)
|
||||
return await asyncio.wait_for(socket_open_helper(), timeout=1)
|
||||
except asyncio.TimeoutError:
|
||||
mpv_stop()
|
||||
|
||||
|
@ -113,14 +113,17 @@ async def mpv_socket_open() -> tuple[StreamReader, StreamWriter] | None:
|
|||
async def mpv_socket_command(
|
||||
reader: StreamReader, writer: StreamWriter, command: dict[str, Any]
|
||||
) -> Mapping[str, Any] | None:
|
||||
if writer.is_closing():
|
||||
return
|
||||
async def command_helper():
|
||||
writer.write((json.dumps(command) + "\n").encode())
|
||||
await writer.drain()
|
||||
|
||||
writer.write((json.dumps(command) + "\n").encode())
|
||||
await writer.drain()
|
||||
reply = await reader.readline()
|
||||
return json.loads(reply.decode())
|
||||
|
||||
reply = await reader.readline()
|
||||
return json.loads(reply.decode())
|
||||
try:
|
||||
return await asyncio.wait_for(command_helper(), timeout=0.1)
|
||||
except asyncio.TimeoutError:
|
||||
return None
|
||||
|
||||
|
||||
def sizeof_fmt(num, suffix="B"):
|
||||
|
|
Loading…
Add table
Reference in a new issue