Verified Lessons Corpus (7)
Every lesson below has executed its positive and negative eval in hard-capped Docker sandboxes.
verified
python-async • v1.1.0
View Lesson →
An aiohttp ClientSession that is never closed before its event loop tears down emits 'Unclosed client session' at GC and leaks connector resources; close it inside the coroutine, ideally via async context manager.
- Unclosed client session
- Unclosed connector
draft
python-async • v1.1.0
View Lesson →
Breaking early out of `async for` over an async generator defers `finally:` cleanup silently to GC / loop teardown — close it explicitly with `await gen.aclose()` or `contextlib.aclosing`.
- resource still held after breaking out of an async for loop
- file handle or lock not released after early break from async generator
verified
python-async • v2.0.0
View Lesson →
asyncio.gather() with default return_exceptions=False propagates the first exception but does NOT cancel sibling tasks — they keep running detached, their results are discarded and their exceptions may never be retrieved; use TaskGroup for cancel-on-failure.
- Task exception was never retrieved
- Side effects from gathered tasks continue after gather already raised
verified
python-async • v1.1.0
View Lesson →
Calling asyncio.run() inside an already-running event loop raises 'asyncio.run() cannot be called from a running event loop'; nest_asyncio is a workaround that causes reentrancy deadlocks in production — await directly or use the framework's sync-to-async bridge.
- RuntimeError: asyncio.run() cannot be called from a running event loop
- RuntimeError: This event loop is already running
draft
python-async • v1.0.0
View Lesson →
Catching generic Exception in async retry loops swallows non-retryable/fatal errors, causing wasted retries, latency spikes, and silent failures; restrict retry catches strictly to allowlisted exception types (e.g., `except retryable as e:` or explicitly re-raise).
- Fatal errors (e.g., auth failure, bad request, validation error) are retried repeatedly instead of failing fast
- Non-retryable exceptions take multiple retry delays before propagating
draft
python-async • v1.0.0
View Lesson →
loop.run_in_executor(None, ...) all share one bounded default ThreadPoolExecutor; saturating it with blocking calls makes every other default-executor call queue and stall. Give bulk blocking work its own executor.
- run_in_executor calls hang or stall under load
- unrelated async task blocked waiting for a free thread pool worker
verified
python-async • v1.0.0
View Lesson →
asyncio.TaskGroup wraps child-task exceptions in an ExceptionGroup, so a plain `except ValueError` around the `async with` block does NOT catch them and the error escapes; use `except*` (Python 3.11+).
- ExceptionGroup: unhandled errors in a TaskGroup
- except clause did not catch exception raised inside TaskGroup