python-async
Use when designing, debugging, or reviewing async Python — AnyIO, `asyncio`, or Trio code, task groups, cancellation, thread offloading, or async tests. Triggers on: `async def` code in the prompt, "CancelledError", an async hang or shutdown that never finishes, event-loop errors ("attached to a different loop", "asyncio.run() cannot be called"), "task group" / "cancel scope", pytest-asyncio or AnyIO test questions, or "uvloop". Pair the framework skill when lifecycle rules belong to Django, Litestar, or FastAPI.
- License 许可
- Unlicense
- 最近更新
- 2026-10-28
- Stars
- ★ 4
- Forks
- 0
01 前言 Front Matter
- name
- python-async
- scope
- python-async
- description
- Use when designing, debugging, or reviewing async Python — AnyIO, `asyncio`, or Trio code, task groups, cancellation, thread offloading, or async tests. Triggers on: `async def` code in the prompt, "CancelledError", an async hang or shutdown that never finishes, event-loop errors ("attached to a different loop", "asyncio.run() cannot be called"), "task group" / "cancel scope", pytest-asyncio or AnyIO test questions, or "uvloop". Pair the framework skill when lifecycle rules belong to Django, Litestar, or FastAPI.
- source_basis
- official docs + source code + README
- last_verified
- 1774396800000
- target_versions
- Python 3.11-3.14, AnyIO 4.x, Trio 0.32+, uvloop 0.18+ on supported CPython/POSIX runtimes
02 资源文件 13
- 参考文档evals/evals.json12.4 KB
- 参考文档evals/trigger-evals.json3.5 KB
- 参考文档references/backend-asyncio.md3.1 KB
- 参考文档references/backend-trio.md2.3 KB
- 参考文档references/backend-uvloop.md2.5 KB
- 参考文档references/cancellation-timeouts.md5.0 KB
- 参考文档references/code-review-checklist.md1.9 KB
- 参考文档references/decision-matrix.md3.1 KB
- 参考文档references/REFERENCE.md2.8 KB
- 参考文档references/streams-synchronization.md2.8 KB
- 参考文档references/structured-concurrency.md5.0 KB
- 参考文档references/testing.md2.7 KB
- 参考文档references/threads-boundaries.md5.2 KB
03 SKILL.md 正文
Python Async Reference
Use this skill for async-enabled Python libraries and applications. Default to AnyIO APIs for portable logic, then surface backend-specific behavior only when raw asyncio, Trio, or uvloop details materially change the answer. Read only the reference files needed for the task.
Critical Rules
- Default to AnyIO for portable logic - Use AnyIO APIs for task groups, cancellation, streams, threads, and tests unless native backend semantics are required.
uvloopis not a third async model - It is anasyncioevent loop implementation and should be treated as an asyncio-only runtime option.- Prefer structured concurrency - Task groups or nurseries beat ad-hoc background task spawning for lifecycle safety.
- Re-raise cancellation after cleanup - Catch cancellation only to clean up or translate context; swallowing it is a bug.
- Shield only bounded cleanup - Do not use shielding as a generic escape hatch from cancellation.
- Do not recommend raw
asyncio.shield()for new portable code - It is too easy to orphan work or hide failures. - Do not nest runners - Do not call
asyncio.run()or similar inside a running or framework-owned loop. - Offload blocking work explicitly - Async syntax does not make blocking file I/O, logging, DNS, or CPU-heavy code safe.
- Treat worker threads as context copies, not extensions - Contextvars are copied into
to_thread.run_sync()and never merge back, and threads cannot be cancelled: long-running worker-thread code must pollfrom_thread.check_cancelled();abandon_on_cancel=Trueonly abandons the wait. - Portability claims require backend-aware tests - Do not claim AnyIO portability if code or tests only run on one backend.
- Benchmark before recommending
uvloop- Treat it as runtime tuning, not a semantic fix. - Prefer repo-local references before external source spelunking - When this skill's reference files already cover the question, answer from them first. Do not spelunk site-packages or unrelated local installs during normal runs unless the task explicitly requires source-level verification beyond the bundled references.
- Make the thread-bridge callable split explicit -
from_thread.run()is for async callables;from_thread.run_sync()is for loop-thread sync callbacks such as setting an AnyIOEvent. Do not collapse them into one interchangeable bucket.
When Not To Use This Skill
- Framework-owned lifecycle rules - Pair the relevant framework skill when startup, shutdown, request lifetimes, or background task ownership belong to Django, Litestar, FastAPI, Starlette, or another framework.
- Distributed task systems - Celery, RQ, Dramatiq, brokers, and cross-process workers are out of scope.
- Low-level event loop internals - Selector internals, custom loop implementations, and CPython internals are not owned here.
- Non-Python async models - gevent, eventlet, greenlets, and non-Python runtimes are out of scope.
- Kernel or network tuning - Production socket tuning, kernel backlog changes, and OS-level performance work are out of scope.
Reference Map
| File | Domain | Use For |
|---|---|---|
references/REFERENCE.md |
Index | Cross-file routing and reading order |
references/decision-matrix.md |
Routing | AnyIO vs native backend vs runtime choice |
references/structured-concurrency.md |
Task lifecycle | Task groups, readiness handshakes, exception groups, ownership |
references/cancellation-timeouts.md |
Cancellation | Cancel scopes, timeouts, shielding, cleanup, async generator finalization, backend differences |
references/streams-synchronization.md |
Coordination | Memory object streams, backpressure, locks, events, capacity limits |
references/threads-boundaries.md |
Boundaries | Thread offloading, thread/loop crossings, blocking portals, loop ownership |
references/testing.md |
Testing | AnyIO pytest plugin, backend matrices, Trio test tools, uvloop test axis |
references/backend-asyncio.md |
Backend specifics | Raw asyncio semantics, task/shield/queue/thread pitfalls |
references/backend-trio.md |
Backend specifics | Checkpoints, cancel scopes, Trio thread rules, Trio testing tools |
references/backend-uvloop.md |
Runtime tuning | What uvloop changes, where to enable it, when not to recommend it |
references/code-review-checklist.md |
Review | Fast checklist for async correctness and portability risks |
Task Routing
- Unsure whether to answer in AnyIO or native backend terms ->
references/decision-matrix.md - Designing or reviewing task spawning / background work ->
references/structured-concurrency.md - Fixing hangs, shutdown bugs, timeouts, or cleanup issues ->
references/cancellation-timeouts.md - Choosing queues/channels/locks/semaphores or backpressure behavior ->
references/streams-synchronization.md - Crossing sync/async or thread/event-loop boundaries ->
references/threads-boundaries.md - Writing async tests or building backend matrices ->
references/testing.md - Raw
asynciocode or APIs in the prompt ->references/backend-asyncio.md - Raw Trio code or Trio-native semantics in the prompt ->
references/backend-trio.md uvloopenablement or performance discussion ->references/backend-uvloop.md- Code review of async correctness ->
references/code-review-checklist.md
Output Expectations
- Name the reference files used.
- State whether the answer is
AnyIO-portable,asyncio-specific,Trio-specific, orasyncio-runtime-specific. - Explain the main lifecycle or cancellation constraint, not just the API syntax.
- When thread crossings matter, name
from_thread.run()andfrom_thread.run_sync()separately and state which callable shape each one expects. - State the minimum verification step: tests, backend matrix, runtime smoke test, or benchmark.
- Call out the highest-risk footgun plainly.
04 同仓库更多 Skills
wizard
Generate an interactive bash wizard that walks a human through a manual procedure — third-party setup, credential provisioning, a one-off migration — opening URLs, capturing values, confirming each step, and writing .env files and CI secrets (GitHub and Gitea/Forgejo Actions).
restore-test-pyramid
Analyze the project's E2E suite and push every assertion that doesn't need a real browser down to a faster integration or unit test, proving each migration honest before thinning E2E.
ponytail-debt
Harvest SHORTCUT markers from the codebase and report them grouped by file, flagging any missing upgrade paths.
humanify
Repair an inherited or human-blocked ticket for agent implementation, or finish its explicit human-only outcome.
fix-pr
Repair an existing pull request's review findings and target-branch conflicts, verify the result, and update the same open PR.
feature-milestones
Reconstruct a fragmented backlog as finishable feature milestones with explicit delivery boundaries and an approval-gated tracker update.