From 72ca7dbe057c00c3a34013d0c56fda0ab9bbfffe Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Mon, 22 Sep 2025 15:10:57 -0400 Subject: [PATCH] asyncio_serial: add force option to set_read_callback If force == true and None is passed as the read callback then the existing reader will be closed and a new reader is created. This can be used to exit an existing reader's iterator without closing the serial connection. Signed-off-by: Eric Callahan --- moonraker/utils/async_serial.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/moonraker/utils/async_serial.py b/moonraker/utils/async_serial.py index 0f6fd59..a375b64 100644 --- a/moonraker/utils/async_serial.py +++ b/moonraker/utils/async_serial.py @@ -55,9 +55,11 @@ class AsyncSerialConnection: server = config.get_server() return AsyncSerialConnection(server, name, port, baud) - def set_read_callback(self, callback: Callable[[bytes], None] | None) -> None: + def set_read_callback( + self, callback: Callable[[bytes], None] | None, force: bool = False + ) -> None: if callback is None: - if self.reader_active: + if not force and self.reader_active: return self._reader.feed_eof() self._reader = asyncio.StreamReader(limit=READER_LIMIT)