Spaces:
Running
Running
| from contextlib import asynccontextmanager | |
| from typing import Optional | |
| import httpx | |
| _client: Optional[httpx.AsyncClient] = None | |
| async def lifespan(app): | |
| global _client | |
| _client = httpx.AsyncClient() | |
| yield | |
| await _client.aclose() | |
| def get_client() -> httpx.AsyncClient: | |
| global _client | |
| if _client is None: | |
| raise RuntimeError("HTTP Client not initialized. Ensure lifespan is used.") | |
| return _client | |