python-asyncio-concurrency

A guide to writing concurrent asynchronous Python with asyncio. Asynchronous code lets one program handle multiple waiting tasks, such as network requests, without stopping the whole program.

In plain words
What is it for?
Use it to run tasks in parallel, add time limits, coordinate shared work, handle cancellation, and move blocking or CPU-heavy work out of the event loop.
Why use it?
It helps prevent blocked event loops, forgotten tasks, missing awaits, incorrect locking, and background work that never finishes or cannot be cancelled.

Skill for Claude CodeCodex

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add skills/vikasudasi/skill-vault/python-asyncio-concurrency
Any agent
npx skills add vikasudasi/skill-vault --skill python-asyncio-concurrency
Clone the repo
git clone --depth 1 https://github.com/vikasudasi/skill-vault

Made for: Claude Code, Codex.

Per session 30 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 412 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 1 finding. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00030 $0.00412
Opus 5 $0.00015 $0.00206
Sonnet 5 $0.00006 $0.00082
Haiku 4.5 $0.00003 $0.00041

Measured 2d ago against content hash 7e5920a19ec0, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

python-asyncio-concurrency scanned grade A with 1 finding against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 2d ago.

The scan reads SKILL.md. This mod also ships 1 executable file (scripts/async_patterns.py), listed below but not scanned — reading those needs a real analyzer, not pattern matching.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Makes network callslowCapability

Not a fault in itself. Listed so you know the mod talks to something, and to what.

async def fetch(url: str) -> str: ...
skill_vault/data/skills/python-asyncio-concurrency/SKILL.md · 59 lines

What it actually says

Correct Python asyncio

Use when writing concurrent async code — background tasks, parallel I/O, or orchestrating many awaitables without blocking the loop.

Run and await

import asyncio


async def fetch(url: str) -> str: ...


async def main() -> None:
    results = await asyncio.gather(fetch("a"), fetch("b"))

Never block the loop

One event loop runs all coroutines — a blocking time.sleep() or sync I/O inside a coroutine stalls everything. Use asyncio.sleep(), re-encode sync work with await asyncio.to_thread(...), or push CPU-bound work to a process.

Tasks and cancellation

  • asyncio.create_task() schedules background work; keep a reference or it may be garbage-collected mid-flight.
  • Use asyncio.timeout(...) (3.11+) for bounds; handle TimeoutError.

Locking across coroutines

lock = asyncio.Lock()
async with lock:
    ...  # critical section

An asyncio.Lock is per-loop — a plain threading.RLock is for threads and won't serialize coroutines correctly. Match the lock to your concurrency model.

Pitfalls

  • Forgetting to await returns a coroutine that never runs → "coroutine was never awaited" warning. Intentional fire-and-forget still needs a task.
  • Don't share mutable state across tasks without a lock.
Files

What ships with it

2 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 2d ago First seen · 59 lines · 30 tokens per session scan A 7e5920a19ec0

Subscribe to this mod's changes

python-asyncio-concurrency is a skill published in the GitHub repository vikasudasi/skill-vault (0 stars, last pushed 17d ago), licensed Apache-2.0. It adds 30 tokens to every session and 412 once invoked, about $0.0002 per session on Opus 5. A static security scan graded it A with 1 finding (makes network calls). No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.

Related

Other skills, from other repositories

python-async-patterns

5 async patterns with full implementations for Python concurrent programming.

bobmatnyc/claude-mpm-agents · 16 tokens

using-asyncio-python

Apply Using Asyncio in Python practices (Caleb Hattingh). Covers Introducing Asyncio (Ch 1: what it is, I/O-bound concurrency), Threads (Ch 2: drawbacks, race conditions, GIL, ThreadPoolExecutor), Asyncio Walk-Through (Ch 3: event loop, coroutines, async def/await, tasks, futures, gather, wait, async with, async for…

booklib-ai/booklib · 190 tokens

debug-assistant

Helps debug Python errors and exceptions.

kongusen/loom-agent · 11 tokens

vulners-api-python-sdk

Use when modifying, testing, documenting, or reviewing the Vulners Python SDK. Covers the v4 architecture (typed sync/async clients, resource namespaces, bulletin model hierarchy, unasync codegen), the preserved legacy v3 surface, uv-based tooling, the 100% branch-coverage gate, safe API-key handling, and defensive…

vulnersCom/api · 79 tokens

pytdbot

Write Telegram bots and userbots with Pytdbot (async TDLib Python client). Use when the user works with Pytdbot, TDLib, or pytdbot.Client.

pytdbot/client · 40 tokens

code-review-python

Deep Python-specific code review covering type annotations, async pitfalls, mutable defaults, threading safety, and domain modeling. Applied in addition to the generic code-review skill when Python code is detected. Invoked when reviewing Python PRs, Py changes, or performing Python-specific quality checks.

soulcodex/agentic · 59 tokens