python-async-concurrency
Skill4 starsChanged 2 months agoApache-2.0View on GitHub
Design or debug Python asyncio tasks, deadlines, cancellation, backpressure, async resource ownership, and shutdown. Use pyo3-async-lifecycle for the Rust bridge itself.
In this repository81 other files it gives its agents.
- agent-cli-designSkill
- agent-tool-boundariesSkill
- behavior-first-implementationSkill
- bounded-prototypeSkill
- bounded-pr-sliceSkill
- building-fdd-validationSkill
- context-efficiencySkill
- cross-language-contractsSkill
- cross-platform-agent-instructionsSkill
- design-interviewSkill
- diagnosis-loopSkill
- domain-languageSkill
- edge-cloud-syncSkill
- handoff-continuitySkill
- immutable-pr-reviewSkill
- memory-context-hygieneSkill
- module-designSkill
- orchestrateSkill
- owner-decision-gateSkill
- parallel-portfolioSkill
- pr-gate-loopSkill
- pyo3-async-lifecycleSkill
- pyo3-buffer-performanceSkill
- pyo3-free-threadingSkill
- pyo3-ownership-errorsSkill
- pyo3-wheel-releaseSkill
- python-api-typingSkill
- python-ci-releaseSkill
- python-data-boundariesSkill
- python-packaging-environmentsSkill
- python-performanceSkill
- python-pytestSkill
- python-reviewSkill
- python-test-designSkill
- python-threading-workersSkill
- python-workflowSkill
- react-components-stateSkill
- react-performanceSkill
- repository-groundingSkill
- rust-api-designSkill
- rust-async-concurrencySkill
- rust-build-diagnosticsSkill
- rust-ci-releaseSkill
- rust-memory-layoutSkill
- rust-nextestSkill
- rust-numerics-simdSkill
- rust-performanceSkill
- rust-protocol-codecsSkill
- rust-python-bindingsSkill
- rust-reviewSkill
- rust-storage-durabilitySkill
- rust-test-designSkill
- rust-unsafe-ffiSkill
- rust-workflowSkill
- rust-workspace-dependenciesSkill
- shadcn-react-componentsSkill
- shadcn-svelte-componentsSkill
- simplify-existing-codeSkill
- source-verificationSkill
- svelte-components-runesSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 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.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 15
Use try/finally and async context managers for cleanup.
- Distinctive: line 25
Use monotonic time for elapsed budgets.
- Distinctive: line 31
Test readiness, overload, cancellation races, partial construction, close twice, and cleanup errors using controlled local fixtures.
- Distinctive: line 35
Read async cases for focused diagnostics.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 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.
Files
Python Async and Cancellation
Map who owns the event loop, tasks, client sessions, queues, and shutdown. Identify the supported Python version and any AnyIO/Trio use; do not introduce a second async framework or call asyncio.run from a library function inside an active loop.
Make task lifetime explicit
Use an existing structured-concurrency pattern or TaskGroup when the supported floor and failure semantics fit. A task group's sibling-cancellation behavior is a design decision, not interchangeable with gather. Retain and supervise tasks created outside a group; do not lose exceptions in fire-and-forget work. Handle ExceptionGroup deliberately at an appropriate boundary.
Use try/finally and async context managers for cleanup. When catching CancelledError for cleanup, normally re-raise it. Cancellation is not an ordinary recoverable request error. Shield only an intentionally owned bounded operation and keep its task handle; shielding without supervising completion leaves orphan work.
Account for eager task execution when the supported Python version or configured task factory enables it: coroutine code can run during task construction, before the caller's next statement. Establish required state before spawning and test synchronous completion as well as suspension. Do not enable eager execution as a blanket optimization. See construction and failure cases when task registration or sibling failure is involved.
Define admission, time, and overload
Bound both queued and active work. Placing a semaphore inside a task does not bound the number of tasks already created. Prefer bounded queues or bounded producers, with an explicit full-queue policy. Specify one logical deadline and how retries consume it; do not reset the total budget at every layer.
Cancellation before admission, during I/O, after a remote write, and during shutdown have different consequences. Preserve idempotency and unknown-outcome semantics. A timeout is not proof that a device write did not occur. Reject blanket retry of mutating operations.
Use monotonic time for elapsed budgets. Distinguish connection, read, and whole-operation timeouts. Timer cancellation is cooperative; do not promise a hard wall-clock bound for code that blocks the loop or suppresses cancellation.
Keep the event loop responsive
Do not call blocking I/O or long native work directly on the loop thread. Use an existing async API or a justified worker seam. Cancelling a to_thread await does not forcibly stop the worker; bound and own that work. Asyncio objects are not general cross-thread primitives: schedule through the loop's supported thread-safe entry points.
Test readiness, overload, cancellation races, partial construction, close twice, and cleanup errors using controlled local fixtures. Verify that shutdown observes every owned task and does not wait while holding a resource those tasks need. For native awaitables, inspect the bridge rather than assuming coroutine semantics.
Return the lifecycle contract, changed behavior, tests, and any remaining inability to cancel or stop work.
Read async cases for focused diagnostics.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
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.

