Python Async Patterns
Problem Statement
Async Python is powerful but error-prone. Race conditions, session leaks, and connection pool issues are common pitfalls in async codebases.
Pattern: AsyncSession Lifecycle
Problem: Session must be scoped to request. Leaking sessions causes stale data and connection exhaustion.
# ✅ CORRECT: Session scoped to request via dependency
async def get_session() -> AsyncGenerator[AsyncSession, None]:
async with async_session() a
[Description truncada. Veja o README completo no GitHub.]