Skip to content

support startup/shutdown events using an async contextmanager  #67

Closed
@graingert

Description

@graingert

eg, I'd like to be able to run background tasks and pool http connections:

@contextlib.asynccontextmanager
async def lifespan_context():
    async with anyio.create_task_group() as tg, httpx.AsyncClient() as client:
        yield {"tg": tg, "client": client}

app = Server("name", lifespan_context=lifespan_context)

anything yielded from the context manager should be available on app.request_context.state

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions