Logo van Python Async

Python Async

Community
0xBakeer
python-async

Using asyncio in Python - async functions, gather with limits, timeouts, cancellation, running blocking code in a thread, async HTTP with httpx, and avoiding the event loop stalls.

Overzicht

Uitgever0xBakeer
RepositoryTandemLLM
Skillnaampython-async
Sterren
75
Forks
14
Meegeleverde bestanden
Alleen instructies
LicentieAGPL-3.0
Links
  • Instructies in Markdown

    Een SKILL.md-bestand dat het model laadt wanneer nodig, zodat het alleen tokens kost als een verzoek er daadwerkelijk bij past.

  • Werkt met elk LLM

    AI-skills zijn gewone Markdown, geen aanbiederspecifieke code. Daardoor werken ze met GPT, Claude, Gemini, Grok of een lokaal model.

  • Compleet zonder extra bestanden

    Alles wat het model nodig heeft, staat in de instructies — geen extra bestanden om te synchroniseren.

  • Open source

    Gepubliceerd door 0xBakeer op GitHub. Lees de broninhoud voordat je de skill installeert.

Installatie

Installeer de AI-skill Python Async in TypingMind om deze met elke LLM te gebruiken, of voeg de skill toe aan een andere agent die SKILL.md kan lezen.

1

Installeren in TypingMind

TypingMind installeert een skill rechtstreeks vanuit de GitHub-map — het leest SKILL.md, bundelt de bijbehorende bestanden en slaat het resultaat lokaal op.

  1. Open de app en ga naar Plug-ins → Skills.
  2. Kies "Installeren via GitHub".
  3. Plak de onderstaande URL van de skillmap en bevestig.
    https://github.com/0xBakeer/TandemLLM/tree/main/packages/library/python-async
  4. Schakel de skill in elke chat in waarin je deze beschikbaar wilt hebben.
Plug-ins → Skills → Nieuwe skill → Via GitHub-URL. Plak vervolgens de map-URL en druk op Doorgaan.
2

Installeren in een andere agent

Elke agent die het Agent Skills-formaat kan lezen, kan deze skill gebruiken — kopieer de map naar de skillmap van die agent.

Claude Code — .claude/skills
git clone --depth 1 https://github.com/0xBakeer/TandemLLM.git /tmp/TandemLLM
mkdir -p .claude/skills
cp -r /tmp/TandemLLM/packages/library/python-async .claude/skills/python-async
Start Claude Code na het kopiëren opnieuw op, zodat de nieuwe skill wordt herkend.

Gebruik deze skill in TypingMind

Schakel Python Async in een willekeurige chat in TypingMind in en het model doet de rest. De naam en beschrijving staan in de systeemprompt. Zodra een verzoek erbij past, laadt het model zelf de volledige instructies — je hoeft de skill nooit handmatig aan te roepen en deze kost pas tokens wanneer je de skill daadwerkelijk gebruikt.

Het model laadt Python Async automatisch zodra een verzoek erbij past.

Werkt met elk AI-model

AI-skills zijn gewone Markdown-instructies in plaats van aanbiederspecifieke code. Daardoor is Python Async niet gebonden aan het model waarvoor de skill is geschreven. Installeer de skill één keer in TypingMind en gebruik deze met GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama of een lokaal model dat je zelf draait — allemaal met je eigen API-sleutels.

  • Alleen geladen wanneer nodig

    De systeemprompt bevat alleen de naam en beschrijving. De instructies worden bij het eerste bijpassende verzoek opgehaald, dus een ongebruikte skill kost niets.

  • Wissel van model tijdens een chat

    Omdat de skill uit instructies bestaat en niet uit code, blijft deze werken als je van model wisselt — het volgende model leest hetzelfde SKILL.md-bestand.

Skillinstructies

Dit is de inhoud van SKILL.md die het model laadt. Lees deze vóór de installatie — een skill bestaat uit instructies die je model zal volgen.

Python asyncio

Rules:

  • Use async only for I/O-bound concurrency (many HTTP calls, sockets, subprocesses). CPU work goes to a process pool; blocking libraries go to asyncio.to_thread.
  • One entry: asyncio.run(main()). No nested asyncio.run, no loop created by hand.
  • Limit concurrency with a Semaphore (10 to 50) and gather with return_exceptions=True; inspect the exceptions, do not drop them.
  • Every await on the network has a timeout: asyncio.wait_for(..., 10) or the client's own timeout.

What goes wrong:

  • A coroutine called without await; nothing runs and a warning appears. Read the warnings.
  • gather on 10,000 tasks at once; rate limits and memory. Semaphore.
  • A sync library inside async def; everything stalls. Measure with a timer around the await.

Check: run the program on real input with a timer, print the count of completed and failed tasks and the total time, and show that the time is near the slowest call, not the sum.

Done when:

  • Total time, completed count and failed count printed for a real run.
  • Wall time is clearly below the serial sum (both numbers in the result).
  • A forced timeout or failure in one task is reported and does not stop the others (log line shown).

Reference

python
import asyncio, time, httpx
async def fetch(client, url, sem):
    async with sem:
        r = await client.get(url, timeout=10); r.raise_for_status(); return len(r.content)
async def main(urls):
    sem = asyncio.Semaphore(20); t0 = time.perf_counter()
    async with httpx.AsyncClient() as client:
        results = await asyncio.gather(*(fetch(client, u, sem) for u in urls), return_exceptions=True)
    ok = [r for r in results if not isinstance(r, Exception)]
    bad = [(u, repr(e)) for u, e in zip(urls, results) if isinstance(e, Exception)]
    print(f"done {len(ok)} failed {len(bad)} in {time.perf_counter()-t0:.2f}s"); print(bad[:5])
    return ok
if __name__ == "__main__":
    asyncio.run(main(["https://example.com"] * 50))

Blocking call in a thread: data = await asyncio.to_thread(read_big_file, path). TaskGroup (3.11+):

python
async with asyncio.TaskGroup() as tg:
    t1 = tg.create_task(job_a()); t2 = tg.create_task(job_b())
print(t1.result(), t2.result())

Subprocess: p = await asyncio.create_subprocess_exec("cmd", "arg", stdout=asyncio.subprocess.PIPE); out, _ = await p.communicate(). Detect loop stalls: asyncio.run(main(), debug=True) logs callbacks slower than 100 ms. Periodic task: while True: await work(); await asyncio.sleep(5) inside a stored task; cancel it on shutdown.

More rules:

  • Cancellation: let CancelledError propagate; clean up in finally. Use asyncio.TaskGroup (3.11+) so a failure cancels siblings.
  • Never block the loop: no time.sleep, no requests, no big file reads without a thread.

More pitfalls:

  • Tasks created with create_task and not kept; garbage collected mid-run. Store the task.

Veelgestelde vragen

Wat doet de AI-skill Python Async?

Using asyncio in Python - async functions, gather with limits, timeouts, cancellation, running blocking code in a thread, async HTTP with httpx, and avoiding the event loop stalls.

Waarom Python Async gebruiken in TypingMind?

Omdat je deze skill één keer installeert en met elk model kunt gebruiken. Python Async bestaat uit gewone Markdown in plaats van aanbiederspecifieke code. Dezelfde skill werkt dus met GPT-5, Claude, Gemini, Grok of een lokaal model, en je kunt midden in een chat van model wisselen zonder dat de skill niet meer werkt. TypingMind werkt met je eigen API-sleutels, dus je betaalt aanbieders rechtstreeks in plaats van een abonnement per gebruikersplek. Je skills en chats blijven in je eigen opslag.

Hoe installeer ik Python Async in TypingMind?

Open Plug-ins → Skills → Installeren vanaf GitHub in TypingMind en plak https://github.com/0xBakeer/TandemLLM/tree/main/packages/library/python-async. TypingMind leest het bestand SKILL.md en installeert het als een skill die je per chat kunt inschakelen.

Welke AI-modellen kunnen Python Async gebruiken?

Elk model dat je in TypingMind koppelt. AI-skills bestaan uit gewone Markdown-instructies in plaats van aanbiederspecifieke code. GPT, Claude, Gemini, Grok en lokale modellen kunnen deze skill dus allemaal laden wanneer een verzoek erbij past.

Hoeveel AI-modellen kan ik met Python Async gebruiken?

Zoveel als je wilt. Zolang een model skills ondersteunt, kun je Python Async ermee gebruiken: GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama en meer. Allemaal in TypingMind met je eigen API-sleutels.

Is de AI-skill Python Async gratis?

Ja. Deze skill is door 0xBakeer op GitHub gepubliceerd onder de licentie AGPL-3.0. Je betaalt alleen je eigen AI-aanbieder voor de tokens die je gebruikt.

Wat zijn AI-skills?

Een AI-skill is een herbruikbare bundel instructies die een AI-model leert hoe het één specifieke taak moet uitvoeren. Deze volgt het open Agent Skills-formaat: een bestand met de naam SKILL.md met een naam en beschrijving, plus eventuele scripts, sjablonen of referentiebestanden die het model nodig heeft. Het model leest de instructies alleen als je verzoek bij de skill past. Een geïnstalleerde skill kost dus niets zolang deze niet wordt gebruikt.

Waarin verschillen AI-skills van plug-ins of MCP-servers?

Een plug-in of MCP-server geeft een model nieuwe tools om aan te roepen: code die ergens wordt uitgevoerd en een resultaat teruggeeft. Een AI-skill geeft het model juist kennis en een werkwijze: hoe het een taak moet aanpakken, welke stappen het moet volgen en hoe goede uitvoer eruitziet. Skills bestaan uit gewone Markdown en hebben dus geen server, API-sleutel of runtime nodig. Ze werken met elk model.

Toon alles

Maak nu je eigen AI-werkruimte

Schrijf je in voor onze nieuwsbrief en blijf op de hoogte van nieuwe functies en toekomstige weggeefacties 👇