python-concurrency-performance
11
总安装量
9
周安装量
#28443
全站排名
安装命令
npx skills add https://github.com/ahgraber/skills --skill python-concurrency-performance
Agent 安装分布
opencode
9
gemini-cli
8
claude-code
8
codex
8
continue
7
antigravity
6
Skill 文档
Python Concurrency and Performance
Overview
Correct concurrency starts with matching the model to the workload, not the developer’s preference. This skill encodes defaults for model selection, cancellation/deadline behavior, and lifecycle safetyâprioritizing explicit control over implicit magic.
Treat these recommendations as preferred defaults. When project constraints demand deviation, call out tradeoffs and compensating controls.
When to Use
- Selecting between
asyncio,threading,multiprocessing, orconcurrent.futures - Propagating deadlines or cancellation through async call chains
- Bounding fan-out, backpressure, or semaphore-guarded concurrency
- Diagnosing race conditions, deadlocks, or priority inversion
- Profiling throughput bottlenecks before and after optimization
- Verifying no task or thread leaks on shutdown or lifecycle transitions
When NOT to Use
- Pure CPU-bound numeric work better served by NumPy/C extensions
- Single-threaded scripting with no concurrent I/O
- Distributed systems coordination (use a workflow/orchestration skill instead)
Quick Reference
- Choose the concurrency model by workload profile (I/O-bound â asyncio/threads; CPU-bound â multiprocessing).
- Keep cancellation and cleanup explicitânever rely on garbage collection to close resources.
- Bound fan-out and backpressure with semaphores or queue limits; unbounded spawning invites OOM.
- Measure before optimizing; re-measure after every change to confirm the win.
- Verify no task/thread leaks on any lifecycle-sensitive change (startup, shutdown, reconnect).
Common Mistakes
- Defaulting to threads for I/O-bound work â
asyncioavoids thread-safety bugs entirely for network I/O; threads add synchronization overhead for no gain. - Ignoring cancellation propagation â a cancelled parent that doesn’t cancel children leaks tasks and holds connections open.
- Unbounded
gather/submitcalls â spawning thousands of tasks without a semaphore or bounded executor starves the event loop or exhausts OS threads. - Optimizing without profiling â guessing at bottlenecks leads to complex code that solves the wrong problem; always profile first.
- Missing shutdown verification â tests that don’t assert clean shutdown mask slow resource leaks that surface only in production under load.
Scope Note
- Treat these recommendations as preferred defaults for common cases, not universal rules.
- If a default conflicts with project constraints or worsens the outcome, suggest a better-fit alternative and explain why it is better for this case.
- When deviating, call out tradeoffs and compensating controls (tests, observability, migration, rollback).
Invocation Notice
- Inform the user when this skill is being invoked by name:
python-concurrency-performance.
References
references/concurrency-models.mdreferences/deadlines-cancellation-lifecycle.mdreferences/leak-detection.md