Logo vun Python Async

Python Async

Communautéit
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.

Iwwersiicht

Editeur0xBakeer
RepositoryTandemLLM
Skill-Nummpython-async
Stären
75
Forks
14
Matgeliwwert Fichieren
Nëmmen Instruktiounen
LizenzAGPL-3.0
Linken
  • Instruktiounen am Markdown-Format

    Eng SKILL.md-Datei, déi de Modell bei Bedarf luet, soudatt nëmmen Token ufalen, wann eng Ufro tatsächlech dozou passt.

  • Funktionéiert mat all LLM

    KI-Skills si reng Markdown, keen ubidderspezifesche Code. Dofir funktionéiert dëse Skill mat GPT, Claude, Gemini, Grok oder engem lokale Modell.

  • Alles an den Instruktiounen

    Alles, wat de Modell brauch, steet an den Instruktiounen — keng zousätzlech Dateien ze synchroniséieren.

  • Open Source

    Vum 0xBakeer op GitHub verëffentlecht. Liest de Quelltext, ier Dir de Skill installéiert.

Installatioun

Installéiert de KI-Skill Python Async an TypingMind, fir e mat all LLM ze benotzen, oder füügt en an en anere KI-Agent an, deen SKILL.md liest.

1

An TypingMind installéieren

TypingMind installéiert e Skill direkt aus sengem GitHub-Dossier — dobäi gëtt SKILL.md gelies, d'Ressourcedateie gi gebëndelt an d'Resultat gëtt lokal gespäichert.

  1. Maacht d'App op a gitt op Plugins → Skills.
  2. Wielt „Vun GitHub installéieren“.
  3. Pecht d'URL vum Skill-Dossier hei drënner an a bestätegt.
    https://github.com/0xBakeer/TandemLLM/tree/main/packages/library/python-async
  4. Aktivéiert de Skill an all Chat, an deem Dir e benotze wëllt.
Plugins → Skills → Skill afügen → Vu GitHub-URL, pecht dann d'URL vum Dossier an a klickt op Weider.
2

An engem anere KI-Agent installéieren

All KI-Agent, deen d'Format Agent Skills liest, kann dëse Skill benotzen — kopéiert den Dossier an de Skill-Verzeechnes vun deem KI-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 nom Kopéieren nei, fir datt den neie Skill erkannt gëtt.

An TypingMind benotzen

Aktivéiert Python Async an engem Chat vun TypingMind, an de Modell iwwerhëlt de Rescht. Den Numm an d'Beschreiwung stinn am System-Prompt. Soubal eng Ufro dozou passt, luet de Modell déi komplett Instruktioune selwer — Dir musst de Skill ni manuell opruffen, an et fale keng Token un, bis en tatsächlech benotzt gëtt.

De Modell luet Python Async automatesch, soubal eng Ufro dozou passt.

Funktionéiert mat all KI-Modell

KI-Skills si reng Markdown-Instruktiounen amplaz vun ubidderspezifeschem Code. Dofir ass Python Async net un de Modell gebonnen, fir deen de Skill geschriwwe gouf. Installéiert en eemol an TypingMind a benotzt e mat GPT-5, Claude, Gemini, Grok, DeepSeek, Mistral, Llama oder engem lokale Modell, deen Dir selwer bedreift — alles mat Ären eegenen API-Keys.

  • Gëtt nëmme gelueden, wann et néideg ass

    De System-Prompt enthält nëmmen den Numm an d'Beschreiwung. D'Instruktioune gi bei der éischter passender Ufro gelueden, soudatt en onbenotzte Skill näischt kascht.

  • De Modell am lafende Chat wiesselen

    Well de Skill aus Instruktiounen amplaz vu Code besteet, funktionéiert en och no engem Modellwiessel — den nächste Modell liest déi selwecht SKILL.md-Datei.

Skill-Instruktiounen

Dëst ass den Inhalt vu SKILL.md, deen de Modell luet. Liest e virun der Installatioun — e Skill besteet aus Instruktiounen, déi Äre Modell befollegt.

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.

Heefeg gestallte Froen

Wat mécht de KI-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.

Firwat Python Async op TypingMind benotzen?

Well Dir en eemol installéiert a mat all Modell benotze kënnt. Python Async besteet aus einfachem Markdown amplaz vun ubidderspezifeschem Code. Dee selwechte Skill funktionéiert also mat GPT-5, Claude, Gemini, Grok oder engem lokale Modell – an Dir kënnt de Modell matzen am Chat wiesselen, ouni datt de Skill ophält ze funktionéieren. TypingMind benotzt Är eegen API-Schlësselen, sou datt Dir d'Ubidder direkt bezuelt amplaz vun engem Abonnement pro Benotzerplaz. Är Skills a Chats bleiwen an Ärem eegene Späicher.

Wéi installéieren ech Python Async an TypingMind?

Maacht an TypingMind Plugins → Skills → Vu GitHub installéieren op a setzt https://github.com/0xBakeer/TandemLLM/tree/main/packages/library/python-async an. TypingMind liest d'Datei SKILL.md an installéiert de Skill, deen Dir pro Chat aktivéiere kënnt.

Wéi eng KI-Modeller kënnen Python Async benotzen?

All Modell, deen Dir an TypingMind verbënnt. KI-Skills sinn einfach Markdown-Instruktiounen an net ubidderspezifesche Code. Dofir kënne GPT, Claude, Gemini, Grok a lokal Modeller dëse Skill lueden, wann eng Ufro dozou passt.

Wéi vill KI-Modeller kann ech mat Python Async benotzen?

Esou vill Dir wëllt. Soulaang e Modell Skills ënnerstëtzt, kënnt Dir Python Async domat benotzen – GPT, Claude, Gemini, Grok, DeepSeek, Mistral, Llama a méi – alles op TypingMind mat Ären eegenen API-Schlësselen.

Ass de KI-Skill Python Async gratis?

Jo. De Skill gëtt vum 0xBakeer ënner der Lizenz AGPL-3.0 op GitHub publizéiert. Dir bezuelt nëmmen Ären eegene KI-Ubidder fir d'Token, déi Dir benotzt.

Wat si KI-Skills?

E KI-Skill ass e weiderverwendbaart Pak vun Instruktiounen, dat engem KI-Modell bäibréngt, wéi en eng bestëmmt Aufgab erfëllt. E follegt dem oppenen Agent Skills-Format: eng Datei SKILL.md mat engem Numm an enger Beschreiwung, plus all Scripten, Virlagen oder Referenzdateien, déi de Modell eventuell brauch. De Modell liest d'Instruktiounen eréischt, wann Är Ufro zum Skill passt. En installéierte Skill kascht also näischt, bis e benotzt gëtt.

Wéi ënnerscheede sech KI-Skills vu Plugins oder MCP-Serveren?

E Plugin oder MCP-Server gëtt engem Modell nei Tools, déi en opruffe kann – Code, deen iergendwou leeft an e Resultat zeréckgëtt. E KI-Skill gëtt dem Modell dogéint Wëssen an eng Virgoensweis: wéi en eng Aufgab ugeet, wéi eng Schrëtt en nokënnt a wéi eng gutt Ausgab ausgesäit. Skills bestinn aus einfachem Markdown, brauche kee Server, keen API-Schlëssel a keng Lafzäitëmfeld a funktionéiere mat all Modell.

All weisen

Elo Ären eegene KI-Workspace ariichten

Abonnéiert Iech op eisen Newsletter, fir iwwer nei Funktiounen an zukünfteg Gewënnspiller informéiert ze ginn 👇