agentleFS
dekozadekoza/oh-my-slop/skills/reference/python-async/SKILL.md

python-async

Skill4 starsChanged 8 months agoUnlicenseView on GitHub

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.

We split this skill into the rules it gives an agent

8 rules. About 0 are common, 4 are distinctive, and 4 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 4

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Use this skill for async-enabled Python libraries and applications.

    line 19
  2. Distinctive:

    Default to AnyIO for portable logic: - Use AnyIO APIs for task groups, cancellation, streams, threads, and tests unless native backend …

    line 23
  3. Distinctive:

    Shield only bounded cleanup: - Do not use shielding as a generic escape hatch from cancellation.

    line 27
  4. Very specific:

    Do not nest runners: - Do not call asyncio.run() or similar inside a running or framework-owned loop.

    line 29
  5. Distinctive:

    Portability claims require backend-aware tests: - Do not claim AnyIO portability if code or tests only run on one backend.

    line 32
  6. Very specific:

    Benchmark before recommending uvloop: - Treat it as runtime tuning, not a semantic fix.

    line 33
  7. Very specific:

    When thread crossings matter, name from_thread.run() and from_thread.run_sync() separately and state which callable shape each one expects.

    line 79
  8. Distinctive:

    Call out the highest-risk footgun plainly.

    line 81

≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
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

  1. Default to AnyIO for portable logic - Use AnyIO APIs for task groups, cancellation, streams, threads, and tests unless native backend semantics are required.
  2. uvloop is not a third async model - It is an asyncio event loop implementation and should be treated as an asyncio-only runtime option.
  3. Prefer structured concurrency - Task groups or nurseries beat ad-hoc background task spawning for lifecycle safety.
  4. Re-raise cancellation after cleanup - Catch cancellation only to clean up or translate context; swallowing it is a bug.
  5. Shield only bounded cleanup - Do not use shielding as a generic escape hatch from cancellation.
  6. Do not recommend raw asyncio.shield() for new portable code - It is too easy to orphan work or hide failures.
  7. Do not nest runners - Do not call asyncio.run() or similar inside a running or framework-owned loop.
  8. Offload blocking work explicitly - Async syntax does not make blocking file I/O, logging, DNS, or CPU-heavy code safe.
  9. 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 poll from_thread.check_cancelled(); abandon_on_cancel=True only abandons the wait.
  10. Portability claims require backend-aware tests - Do not claim AnyIO portability if code or tests only run on one backend.
  11. Benchmark before recommending uvloop - Treat it as runtime tuning, not a semantic fix.
  12. 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.
  13. 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 AnyIO Event. 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

FileDomainUse For
references/REFERENCE.mdIndexCross-file routing and reading order
references/decision-matrix.mdRoutingAnyIO vs native backend vs runtime choice
references/structured-concurrency.mdTask lifecycleTask groups, readiness handshakes, exception groups, ownership
references/cancellation-timeouts.mdCancellationCancel scopes, timeouts, shielding, cleanup, async generator finalization, backend differences
references/streams-synchronization.mdCoordinationMemory object streams, backpressure, locks, events, capacity limits
references/threads-boundaries.mdBoundariesThread offloading, thread/loop crossings, blocking portals, loop ownership
references/testing.mdTestingAnyIO pytest plugin, backend matrices, Trio test tools, uvloop test axis
references/backend-asyncio.mdBackend specificsRaw asyncio semantics, task/shield/queue/thread pitfalls
references/backend-trio.mdBackend specificsCheckpoints, cancel scopes, Trio thread rules, Trio testing tools
references/backend-uvloop.mdRuntime tuningWhat uvloop changes, where to enable it, when not to recommend it
references/code-review-checklist.mdReviewFast 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 asyncio code or APIs in the prompt -> references/backend-asyncio.md
  • Raw Trio code or Trio-native semantics in the prompt -> references/backend-trio.md
  • uvloop enablement 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, or asyncio-runtime-specific.
  • Explain the main lifecycle or cancellation constraint, not just the API syntax.
  • When thread crossings matter, name from_thread.run() and from_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.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

Reviews can't be read right now.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.