From 6ad9df81e6aa9a0df2f1cd4dd697b1c9682f398b Mon Sep 17 00:00:00 2001 From: toros Date: Tue, 8 Sep 2026 23:42:36 +0500 Subject: [PATCH] =?UTF-8?q?fix(core):=20SerialConsole.read=20=D1=83=D1=81?= =?UTF-8?q?=D1=82=D0=BE=D0=B9=D1=87=D0=B8=D0=B2=20=D0=BA=20'readiness=20to?= =?UTF-8?q?=20read=20but=20no=20data'=20=D0=BD=D0=B0=20RPi/USB-serial?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit pyserial на Raspberry Pi временами кидает SerialException (readiness but no data) на простоях порта — читаем как пустоту и продолжаем, а не роняем WS-консоль. --- atxpi/core/hardware.py | 7 ++++++- atxpi/webui/server.py | 15 ++++++++++----- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/atxpi/core/hardware.py b/atxpi/core/hardware.py index 1ea6a3e..bb6cd41 100644 --- a/atxpi/core/hardware.py +++ b/atxpi/core/hardware.py @@ -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: diff --git a/atxpi/webui/server.py b/atxpi/webui/server.py index efeef39..b45571b 100644 --- a/atxpi/webui/server.py +++ b/atxpi/webui/server.py @@ -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: