From f547201c98045887ce186451ee25031fd8007745 Mon Sep 17 00:00:00 2001 From: David Gwilliam Date: Wed, 24 Jun 2026 05:23:19 -0700 Subject: [PATCH] fix: non-blocking response drain using setblocking(False) --- scripts/led-matrix-viz.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/scripts/led-matrix-viz.py b/scripts/led-matrix-viz.py index d14d792..92be3d5 100755 --- a/scripts/led-matrix-viz.py +++ b/scripts/led-matrix-viz.py @@ -74,8 +74,6 @@ def main(): _poll.register(sock, POLLIN) - router_resp = b"" - active_notes = set() last_sent_params = None pending_bytes = None @@ -145,13 +143,17 @@ def main(): if ok: pending_bytes = None frames_sent += 1 - # Drain exactly one response to keep router buffer clear + # Drain pending responses so router buffer stays clear + router.setblocking(False) try: - router.settimeout(0.001) - router.recv(4096) - except (BlockingIOError, socket.timeout, OSError): + while True: + chunk = router.recv(4096) + if not chunk: + break + except (BlockingIOError, OSError): pass finally: + router.setblocking(True) router.settimeout(0.01) else: frames_dropped += 1