← ClaudeAtlas

async-python-patternslisted

Use when writing Python asyncio code — picking between gather / TaskGroup / wait, structured concurrency, timeouts, cancellation, sync-bridging — decision framework only, cookbook externalized.
event4u-app/agent-config · ★ 7 · AI & Automation · score 84
Install: claude install-skill event4u-app/agent-config
# async-python-patterns Decision framework for picking the right Python asyncio primitive. **The pattern cookbook lives upstream** (links in § Provenance) — this skill is the predicate, not the recipe library. Sunset-policy compliant: the 600+ lines of language-specific cookbook stay in authoritative Python docs. ## When to use - Designing a new async I/O-bound service (FastAPI, aiohttp, async DB client). - Reviewing a diff that introduces `asyncio.gather`, `asyncio.create_task`, `TaskGroup`, `as_completed`, or `wait_for`. - Mixing sync and async code (calling sync libs from async context, or vice versa). - Diagnosing event-loop blocking, never-awaited warnings, or cancellation leaks. Do NOT use when: - The work is CPU-bound — async will not help; route to multiprocessing or threadpool. - The runtime is not Python — read the host runtime's concurrency guide. - The fix is a single missing `await` — read the upstream tutorial directly. ## Decision framework ### Step 1 — Verify async is the right tool ``` Workload is: I/O-bound, many concurrent waits → async fits (network, disk, IPC). CPU-bound (parsing, math, crypto) → async is wrong; use ProcessPoolExecutor. Mixed → async shell + run_in_executor for CPU bursts. Single sequential call → don't introduce async; sync is simpler. ``` ### Step 2 — Pick the concurrency primitive ``` Run N independent coroutines, ALL must complete: Same trust level, exceptions cancel siblin