INNER CODE UNIT · Python
_port_in_use
ghost-in-the-droid/android-agent · gitd/cli.py:563
def _port_in_use(port: int, host: str = "127.0.0.1") -> bool:
import socket
probe_host = "127.0.0.1" if host in ("0.0.0.0", "") else host
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
s.settimeout(0.5)
return s.connect_ex((probe_host, port)) == 0
def collect_doctor_checks() -> list[dict]:
"""Preflight environment checks. Returns a list of
{name, status: ok|warn|fail, detail, hint} dicts — no printing, so it's
unit-testable. `cmd_doctor` renders and sets the exit code from these.
"""
checks: list[dict] = []
# Python version
py = f"{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}"