Skip to content

Commit adc6816

Browse files
committed
fix attempt
1 parent 3d9c039 commit adc6816

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

lapdog/cli.py

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@
1515
from typing import List
1616
from typing import Optional
1717
from typing import Tuple
18+
import urllib.error
19+
import urllib.request
1820
import uuid
1921

20-
import requests
21-
2222
from lapdog import backfill_claude
2323
from lapdog import backfill_codex
2424
from lapdog import backfill_pi
@@ -159,6 +159,19 @@ def _url_for_port(port: int) -> str:
159159
return f"http://127.0.0.1:{port}/info"
160160

161161

162+
def _http_get_status(url: str, timeout: float) -> int:
163+
"""GET url and return the HTTP status code.
164+
165+
Uses an empty ProxyHandler so macOS _scproxy.get_proxy_settings is never
166+
called. That call crashes inside a forked child on Python 3.13 / macOS
167+
because the parent process has internal threads at fork time, leaving
168+
CoreFoundation's logging lock state corrupt in the child.
169+
"""
170+
opener = urllib.request.build_opener(urllib.request.ProxyHandler({}))
171+
with opener.open(url, timeout=timeout) as resp:
172+
return int(resp.status)
173+
174+
162175
def _lapdog_alive(timeout: float = 2.0) -> bool:
163176
"""Check if the lapdog we started is running (pid file + process exists + /info responds)."""
164177
pid, port = _read_pid_file()
@@ -167,8 +180,7 @@ def _lapdog_alive(timeout: float = 2.0) -> bool:
167180
if not _process_exists(pid):
168181
return False
169182
try:
170-
r = requests.get(_url_for_port(port), timeout=timeout)
171-
return r.status_code == 200
183+
return _http_get_status(_url_for_port(port), timeout=timeout) == 200
172184
except Exception:
173185
return False
174186

@@ -268,8 +280,7 @@ def _port_in_use(port: Optional[int] = None) -> bool:
268280
if port is None:
269281
port = _resolved_port()
270282
try:
271-
r = requests.get(_url_for_port(port), timeout=1)
272-
return r.status_code == 200
283+
return _http_get_status(_url_for_port(port), timeout=1) == 200
273284
except Exception:
274285
return False
275286

@@ -358,9 +369,11 @@ def cmd_status() -> None:
358369
sys.exit(1)
359370
url = _url_for_port(port)
360371
try:
361-
requests.get(url, timeout=2).raise_for_status()
372+
status = _http_get_status(url, timeout=2)
373+
if status >= 400:
374+
raise OSError(f"HTTP {status}")
362375
print(f"[lapdog] Lapdog running at {url} (pid={pid}, logs: {_log_file_path()})", file=sys.stderr)
363-
except requests.RequestException as e:
376+
except Exception as e:
364377
print(f"[lapdog] Lapdog not reachable at {url}: {e}", file=sys.stderr)
365378
sys.exit(1)
366379

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
fixes:
3+
- |
4+
lapdog: Fixes an issue where the Python process would occasionally crash when running lapdog

0 commit comments

Comments
 (0)