python-async-concurrency

Designs and debugs Python asyncio code with structured concurrency, bounded parallelism, and cancellation safety.

1|Updated Feb 25, 2026
One-click install
npx skills add https://github.com/cjthompson/claude-code-config --skill python-async-concurrency-cjthompson
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: python-async-concurrency
Source: https://github.com/cjthompson/claude-code-config/tree/main/plugins/python-development/skills/python-async-concurrency
Command: npx skills add https://github.com/cjthompson/claude-code-config --skill python-async-concurrency-cjthompson

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Writing correct concurrent Python code is error-prone: unbounded task creation, leaked resources, swallowed cancellations, and unclear failure propagation cause hangs and subtle bugs. This Skill provides concrete decision rules for choosing a concurrency model and implementing asyncio code safely. ## Core Features & Use Cases - Concurrency model selection: Decide between synchronous code, asyncio, threads, and processes based on I/O vs CPU-bound workloads. - Structured asyncio patterns: Use TaskGroup for task lifetimes, semaphores or queues to bound fan-out, and asyncio.timeout for operation deadlines. - Cancellation and failure handling: Propagate CancelledError correctly, clean up resources with context managers, and define explicit policies for ExceptionGroup handling. - Use Case: When building a service that fetches data from hundreds of APIs concurrently, apply this Skill to bound parallelism with a semaphore, enforce per-request timeouts, and ensure partial failures cancel or collect cleanly. ## Quick Start Review my async Python code and apply structured concurrency with bounded parallelism, timeouts, and safe cancellation handling.

Frequently Asked Questions about python-async-concurrency

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I structure concurrent asyncio tasks in Python?

Use asyncio.TaskGroup to manage child-task lifetimes and get grouped failure propagation automatically. Bound fan-out with a semaphore, queue, or worker pool instead of creating unbounded tasks, especially from untrusted input.

When should I use asyncio vs threads vs processes in Python?

Use asyncio for many cooperating I/O operations with async-aware libraries, threads for blocking I/O that cannot be made async, and processes or interpreters for CPU-bound work. Prefer synchronous code when concurrency adds no material benefit.

How do I handle cancellation in asyncio correctly?

Let CancelledError propagate by default. Catch it only when cleanup is necessary, perform the cleanup, then re-raise it so the cancellation contract is preserved and tasks terminate properly.

Why does my async Python code hang or block the event loop?

Blocking calls on the event-loop thread freeze all concurrent tasks. Offload unavoidable blocking calls explicitly, and add asyncio.timeout at meaningful operation boundaries so stuck operations fail instead of hanging silently.

How should I handle exceptions from multiple asyncio tasks?

Define upfront whether one failure cancels siblings, gets collected, or is retried. Handle ExceptionGroup only at a boundary that can make that policy decision, and test partial failure, timeout, and cancellation paths.