Master Python asyncio with coroutines, task groups, event loops, and concurrent programming patterns.
Build an async Python application for the following scenario: Use Case: [WEB SERVER/WEB SCRAPER/DATA INGESTION/REAL-TIME PROCESSING/CHAT APPLICATION] Concurrency Model: [IO-BOUND TASKS/MIXED IO AND CPU/EVENT-DRIVEN] External Services: [HTTP APIs/DATABASES/MESSAGE QUEUES/FILE SYSTEMS] Performance Target: [CONCURRENT CONNECTIONS/THROUGHPUT/LATENCY] Python Version: [3.10/3.11/3.12+] Framework: [ASYNCIO/TRIO/ANYIO/NONE] Develop the async application covering: 1. Asyncio fundamentals with proper event loop management, coroutine definition using async def, awaiting results from IO operations, and understanding the difference between coroutines, tasks, and futures with practical examples of each 2. Task management using asyncio.create_task for concurrent execution, TaskGroup for structured concurrency with automatic cancellation on failure, gathering results from multiple coroutines, and timeout handling with asyncio.wait_for and asyncio.timeout context managers 3. Async iteration patterns implementing async generators with async for loops, async context managers for resource management, aiofiles for non-blocking file operations, and async comprehensions for concise data transformation pipelines 4. Connection pooling and resource management with aiohttp ClientSession for HTTP requests, asyncpg or databases library for PostgreSQL, aioredis for Redis operations, and proper lifecycle management ensuring connections are closed on application shutdown 5. Synchronization primitives using asyncio.Lock for mutual exclusion, Semaphore for concurrency limiting, Event for signaling between tasks, Queue for producer-consumer patterns, and Barrier for coordinating task groups at synchronization points 6. Error handling and debugging with try/except in coroutines, exception groups for TaskGroup failures, asyncio debug mode for detecting common mistakes, custom exception handling for cancelled tasks, and structured logging in async contexts with correlation IDs Include performance benchmarks comparing sync versus async approaches and guidance on when async is genuinely beneficial.
Or press ⌘C to copy