Back to catalog / Developer tools
Python asyncio: adopt async only for concurrent I/O needs
Design event-loop behavior, task concurrency, cancellation, timeouts, and blocking-work offload.
Skills
Estimate concurrent network/database I/O versus CPU work first; a low-concurrency script may be simpler synchronously. If using asyncio, keep the call path async, use async clients and pooled connections, and avoid blocking the event loop. Bound tasks with TaskGroup/semaphores, propagate cancellation/errors, and time out external calls. Offload CPU-heavy work with `asyncio.to_thread()` or a process pool. Test cancellation, cleanup, and slow dependencies, and use measurements to justify throughput gains.
Permissions
Prerequisites
- For Python APIs, network clients, WebSockets, or tasks with substantial concurrent I/O.
- Confirm the workload is I/O-bound; simple scripts or CPU-heavy work may suit sync/process pools.
Permissions
- May change async call paths, client lifecycle, and task scheduling.
- Blocking I/O stalls the event loop; do not convert solely for presumed speed.
Limitations
Keep call paths consistently sync or async; offload CPU work and propagate cancellation/errors to task owners.
Pinned upstream source
- Repository
- wshobson/agents
- File path
- plugins/python-development/skills/async-python-patterns/SKILL.md
- Pinned commit
46891e7e60da0e52baf1050b7b6391b64e84c6d9- Source checked
- 2026-10-14 · Reviewed against the pinned upstream source
Repository metrics
These values describe the upstream repository, not popularity or likes for an individual skill or playbook.
- Stars
- Not collected
- Forks
- Not collected
- Observed at
- Not collected
No metrics snapshot is available yet.
License: MIT
Compatible tools
asyncio event loop · pytest-asyncio · Thread/process executors
Main topic
Take a coding Agent change from context to verification