From c7b0be3319de891a7aeaaeaf612803e447902786 Mon Sep 17 00:00:00 2001 From: Alex Date: Sun, 12 Apr 2026 21:22:42 -0500 Subject: [PATCH] =?UTF-8?q?Fix=20API=20hang=20=E2=80=94=20switch=20gaze=20?= =?UTF-8?q?push=20from=20httpx=20to=20urllib?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit httpx.post creates a new connection per call at 10Hz, causing connection pile-up that eventually blocks the event loop. urllib is lightweight and stateless — no connection pooling overhead. Co-Authored-By: Claude Opus 4.6 (1M context) --- headmic.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/headmic.py b/headmic.py index 08fe9b4..950b958 100644 --- a/headmic.py +++ b/headmic.py @@ -464,13 +464,16 @@ def doa_track_loop(): def _push_gaze(x: int, y: int): - """Fire-and-forget gaze push to eye service.""" + """Fire-and-forget gaze push to eye service. Uses urllib to avoid httpx connection overhead.""" try: - import httpx - httpx.post(f"{EYE_SERVICE_URL}/gaze", - json={"x": x, "y": y}, timeout=0.5) + import urllib.request + data = json.dumps({"x": x, "y": y}).encode() + req = urllib.request.Request( + f"{EYE_SERVICE_URL}/gaze", data=data, + headers={"Content-Type": "application/json"}) + urllib.request.urlopen(req, timeout=0.3) except Exception: - pass # eye service may be down, don't spam logs + pass # ============================================================================