Functions
run_lifespan
2
AsyncIterator[dict[str, …
▼
Run the ASGI lifespan protocol as an async context manager.
Sends lifespan.sta…
async
run_lifespan
2
AsyncIterator[dict[str, …
▼
async def run_lifespan(app: ASGIApp, config: ServerConfig) -> AsyncIterator[dict[str, Any]]
Run the ASGI lifespan protocol as an async context manager.
Sends lifespan.startup on entry, waits for the app to respond with lifespan.startup.complete, yields control to the caller, then sends lifespan.shutdown on exit.
If the app doesn't support lifespan (raises an exception or returns silently during startup), the lifespan is treated as a no-op.
The lifespan scope includes a "state" dict that the app can populate during startup. This same dict is returned to the caller and should be injected into all request scopes as scope["state"] (ASGI 3.0 spec).
Parameters
| Name | Type | Description |
|---|---|---|
app |
ASGIApp |
The ASGI application. |
config |
ServerConfig |
Server configuration. |
Returns
AsyncIterator[dict[str, Any]]