-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.py
More file actions
26 lines (19 loc) · 810 Bytes
/
Copy pathclient.py
File metadata and controls
26 lines (19 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import logging
import httpx
logger = logging.getLogger("opencode-proxy")
_client: httpx.AsyncClient | None = None
async def get_client() -> httpx.AsyncClient:
"""Return the module-level shared httpx client, creating it if necessary."""
global _client
if _client is None or _client.is_closed:
_client = httpx.AsyncClient(
timeout=httpx.Timeout(connect=10.0, read=300.0, write=10.0, pool=10.0),
limits=httpx.Limits(max_connections=100, max_keepalive_connections=20),
)
return _client
async def close_client() -> None:
"""Close the shared httpx client. Called during application shutdown."""
global _client
if _client is not None and not _client.is_closed:
await _client.aclose()
logger.info("Shared httpx client closed")