Coverage for gco / services / uvicorn_runtime.py: 100.00%
8 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-10-28 16:19 +0000
« prev ^ index » next coverage.py v7.13.5, created at 2026-10-28 16:19 +0000
1"""Report which event loop and HTTP parser uvicorn's ``auto`` selection resolved.
3The four uvicorn-served images ship ``uvloop`` and ``httptools`` (see the
4``image-*`` groups in pyproject.toml) so uvicorn's default ``loop="auto"`` /
5``http="auto"`` selection picks the libuv event loop and the llhttp parser.
6The services deliberately keep those defaults -- a developer checkout without
7the wheels still serves on the stdlib loop and h11 -- and instead log what
8was resolved at startup, so a pod log states which implementations are in
9effect. The integration:docker:* jobs assert the fast path inside every
10built image; this module only makes the resolution observable.
11"""
13from __future__ import annotations
15from collections.abc import Callable
18def _qualified_name(obj: Callable[..., object]) -> str:
19 """Dotted name of a class or factory function (both are callables with a qualname)."""
20 return f"{obj.__module__}.{obj.__qualname__}"
23def describe_uvicorn_runtime() -> tuple[str, str]:
24 """Return ``(loop, http)``: the implementations uvicorn's ``auto`` mode resolves to.
26 Both names come from the very objects uvicorn consults, not from a
27 parallel ``import`` probe, so the log line cannot disagree with the server.
28 """
29 from uvicorn.loops.auto import auto_loop_factory
30 from uvicorn.protocols.http.auto import AutoHTTPProtocol
32 return _qualified_name(auto_loop_factory()), _qualified_name(AutoHTTPProtocol)