- Home
- Skills
- Manutej
- Luxor Claude Marketplace
- Asyncio Concurrency Patterns
asyncio-concurrency-patterns_skill
- Shell
40
GitHub Stars
5
Bundled Files
2 months ago
Catalog Refreshed
4 months ago
First Indexed
Readme & install
Copy the install command, review bundled files from the catalogue, and read any extended description pulled from the listing source.
Installation
Preview and clipboard use veilstrat where the catalogue uses aiagentskills.
npx veilstrat add skill manutej/luxor-claude-marketplace --skill asyncio-concurrency-patterns- CONTEXT7_SNIPPETS.md8.7 KB
- EXAMPLES.md54.1 KB
- README.md14.0 KB
- SKILL.md41.2 KB
- SUMMARY.txt4.7 KB
Overview
This skill is a complete guide to asyncio concurrency patterns for building high-performance asynchronous Python applications. It distills event loops, coroutines, tasks, futures, synchronization primitives, async context managers, and production-ready task management into practical patterns. You get clear examples for common problems like rate limiting, producer/consumer workflows, and graceful cancellation.
How this skill works
The skill inspects and explains core asyncio primitives (event loop, coroutines, tasks, futures) and maps them to concrete concurrency patterns such as gather, wait, semaphores, locks, events, and queues. It demonstrates how to create, name, cancel, and handle exceptions in tasks, manage event loops and executors for blocking code, and implement async context managers for safe resource handling. Each pattern includes when to use it, example code, and operational tips for production use.
When to use it
- Building I/O-bound systems that must handle many concurrent connections
- Implementing web servers, API clients, websockets, or real-time dashboards
- Coordinating multiple async operations with proper error handling and cancellation
- Limiting concurrency or rate-limiting access to external services
- Creating robust producer/consumer pipelines and background job processors
Best practices
- Prefer asyncio.run() for simple programs and avoid mixing event loop creation patterns
- Use async context managers for resource setup/teardown (HTTP sessions, DB connections)
- Limit concurrency with Semaphore to prevent resource exhaustion and respect rate limits
- Handle task cancellation explicitly and re-raise CancelledError after cleanup
- Use gather(return_exceptions=True) or inspect task.exception() to collect failures without dropping exceptions
Example use cases
- Parallel HTTP requests with aiohttp and asyncio.gather to reduce latency
- Background worker pool using asyncio.Queue for producer/consumer job processing
- Connection-limited scrapers using asyncio.Semaphore to cap concurrent requests
- Graceful shutdown of long-running tasks with task.cancel() and cleanup in CancelledError handlers
- Running blocking CPU or I/O in ThreadPoolExecutor via loop.run_in_executor() to keep the event loop responsive
FAQ
Use gather when you need all results in input order and want a simple API; use wait when you need flexible strategies (first completed, first exception) or to cancel remaining tasks based on partial results.
How do I safely cancel tasks and clean up resources?
Call task.cancel(), catch asyncio.CancelledError inside the task to run cleanup, then await the task (suppress CancelledError when appropriate) to ensure finalization.