Python Asyncio taste
# Python Asyncio taste of a backend developer who never blocks the event loop - Use asyncio only for I/O-bound work like network calls and databases; CPU-heavy work goes to a process pool. Confidence: 0.90 - Start the pr
Works with
claude-code (compatible), claude (compatible), codex (compatible), chatgpt (compatible), gemini-cli (compatible), cursor (compatible), copilot (compatible), opencode (compatible), amp (compatible), roo (compatible), kiro (compatible), goose (compatible), junie (compatible), trae (compatible), cline (compatible), continue (compatible), antigravity (compatible), windsurf (compatible), augment (compatible), qwen-code (compatible), aider (compatible)
Content
Python Asyncio taste of a backend developer who never blocks the event loop
- Use asyncio only for I/O-bound work like network calls and databases; CPU-heavy work goes to a process pool. Confidence: 0.90
- Start the program with a single
asyncio.run(main())and never create or manage event loops by hand. Confidence: 0.90 - Use
asyncio.TaskGroupfor running tasks together so a failure cancels the siblings and nothing leaks. Confidence: 0.85 - Never fire and forget with
create_taskwithout keeping a reference; lost tasks get garbage collected and errors vanish. Confidence: 0.90 - Put a timeout on every network call with
asyncio.timeout(); waiting forever is a bug. Confidence: 0.90 - Limit concurrency with a
Semaphoreinstead of starting thousands of requests at once. Confidence: 0.85 - Never call blocking libraries like
requestsortime.sleepinside a coroutine. Confidence: 0.95 - Wrap unavoidable blocking calls in
asyncio.to_threadand keep them short. Confidence: 0.80 - Use async-native clients such as
httpxorasyncpg, and share one client per app instead of one per request. Confidence: 0.85 - Treat
CancelledErroras normal: clean up infinallyand re-raise it, never swallow it. Confidence: 0.90 - Avoid
asyncio.gatherwithoutreturn_exceptionsfor independent jobs where one failure should not hide the others. Confidence: 0.70 - Use
asyncio.Queuewith a fixed number of worker tasks for producer and consumer pipelines. Confidence: 0.80 - Close clients, sessions and connections with
async withso shutdown is clean. Confidence: 0.85 - Turn on asyncio debug mode in development to catch slow callbacks and never-awaited coroutines. Confidence: 0.75
- Keep sync and async code paths separate instead of writing clever wrappers that run both. Confidence: 0.75
- Do not mix threads and the event loop unless you use
run_coroutine_threadsafeon purpose. Confidence: 0.80 - Test async code with
pytest-asynciooranyioand give tests their own short timeouts. Confidence: 0.80 - Use
contextvarsfor request IDs and tracing data instead of globals. Confidence: 0.75 - Consider
uvlooponly after measuring; the default loop is fast enough for most services. Confidence: 0.65 - Handle SIGTERM by cancelling the main task and waiting for workers to finish in-flight jobs. Confidence: 0.80
Source and license
- Source
- Prompts Chat
- Original
- f/awesome-chatgpt-prompts/prompts.csv#python-asyncio-taste
- License
- MIT