fix(core): SerialConsole.read устойчив к 'readiness to read but no data' на RPi/USB-serial
pyserial на Raspberry Pi временами кидает SerialException (readiness but no data) на простоях порта — читаем как пустоту и продолжаем, а не роняем WS-консоль.
This commit is contained in:
@@ -96,7 +96,12 @@ class SerialConsole(ConsoleBackend):
|
||||
if not self._ser:
|
||||
raise RuntimeError("консоль не открыта")
|
||||
self._ser.timeout = timeout
|
||||
return self._ser.read(4096)
|
||||
try:
|
||||
return self._ser.read(4096)
|
||||
except Exception:
|
||||
# Raspberry Pi + USB-serial: на простоях порт может сообщать
|
||||
# "readiness to read but no data" — это не фатально, читаем дальше.
|
||||
return b""
|
||||
|
||||
|
||||
def make_power() -> PowerBackend:
|
||||
|
||||
+10
-5
@@ -158,13 +158,18 @@ async def ws_console(ws: WebSocket):
|
||||
await ws.send_bytes(("\r\nATXPI console ready. driver=%s\r\n" % DRIVER).encode())
|
||||
|
||||
async def reader():
|
||||
try:
|
||||
while True:
|
||||
while True:
|
||||
try:
|
||||
data = await asyncio.to_thread(console.read, 0.25)
|
||||
if data:
|
||||
except Exception as e:
|
||||
log.warning("console.read error: %s", e)
|
||||
break
|
||||
if data:
|
||||
try:
|
||||
await ws.send_bytes(data)
|
||||
except Exception:
|
||||
pass
|
||||
except Exception as e:
|
||||
log.warning("ws handle_console send error: %s", e)
|
||||
break
|
||||
|
||||
read_task = asyncio.create_task(reader())
|
||||
try:
|
||||
|
||||
Reference in New Issue
Block a user