python-async-patterns
Installation
SKILL.md
Async Programming Patterns
Concurrent Task Execution
# Pattern 1: Gather with timeout and error handling
async def process_concurrent_tasks(
tasks: list[Coroutine[Any, Any, T]],
timeout: float = 10.0
) -> list[T | Exception]:
"""Process tasks concurrently with timeout and exception handling."""
try:
async with asyncio.timeout(timeout): # Python 3.11+
# return_exceptions=True prevents one failure from cancelling others
return await asyncio.gather(*tasks, return_exceptions=True)
except asyncio.TimeoutError:
logger.warning("Tasks timed out after %s seconds", timeout)
raise