Fähigkeiten async-python-patterns

async-python-patterns

Sicher ⚙️ Externe Befehle🌐 Netzwerkzugriff📁 Dateisystemzugriff

掌握 Python 非同步模式

Auch verfügbar von: wshobson

在 Python 中建立非同步應用程式需要了解複雜的並發執行、工作管理和效能最佳化模式。本技能提供關於 asyncio 基礎知識、現實世界的模式和最佳實踐的全面指導,以建立高效能的非阻塞系統。

Unterstützt: Claude Codex Code(CC)
📊 69 Angemessen
1

Die Skill-ZIP herunterladen

2

In Claude hochladen

Gehe zu Einstellungen → Fähigkeiten → Skills → Skill hochladen

3

Einschalten und loslegen

Teste es

Verwendung von "async-python-patterns". How do I prevent blocking the event loop when running CPU-intensive tasks in async Python code?

Erwartetes Ergebnis:

  • Use asyncio.to_thread() (Python 3.9+) or loop.run_in_executor() to offload blocking CPU work to a thread pool
  • Never use time.sleep() in async code - use await asyncio.sleep() instead
  • Example pattern: wrap CPU-intensive functions with run_in_executor to keep the event loop responsive

Verwendung von "async-python-patterns". What is the difference between asyncio.create_task() and asyncio.gather()?

Erwartetes Ergebnis:

  • create_task() schedules a single coroutine to run soon, returning a Task object you can await later
  • gather() runs multiple coroutines concurrently and waits for all to complete, returning results as a list
  • Use create_task() when you need to manage individual tasks; use gather() for fire-and-forget concurrent execution

Verwendung von "async-python-patterns". How do I implement a timeout for an async function that might hang?

Erwartetes Ergebnis:

  • Use asyncio.wait_for() to wrap your async call with a timeout value
  • Catch asyncio.TimeoutError to handle timeout scenarios gracefully
  • Example: result = await asyncio.wait_for(async_operation(), timeout=5.0)

Sicherheitsaudit

Sicher
v5 • 1/16/2026

Pure educational documentation containing Python asyncio code examples. All static findings are false positives from the analyzer misinterpreting markdown code blocks and documentation text. No executable code, scripts, network calls, file operations, or external commands exist in this skill.

2
Gescannte Dateien
871
Analysierte Zeilen
3
befunde
5
Gesamtzahl Audits
Auditiert von: claude Audit-Verlauf anzeigen →

Qualitätsbewertung

38
Architektur
100
Wartbarkeit
85
Inhalt
22
Community
100
Sicherheit
87
Spezifikationskonformität

Was du bauen kannst

建立非同步 Web API

學習使用 FastAPI、aiohttp 或 Sanic 建立高效能非同步 API 的模式

並發 I/O 操作

實現高效的並發資料庫、檔案和網路操作,而不會發生阻塞

即時應用程式

開發 WebSocket 伺服器、聊天系統和事件驅動的應用程式

Probiere diese Prompts

基本非同步模式
Show me how to use asyncio.gather() to run multiple async functions concurrently in Python
錯誤處理
How do I properly handle errors and timeouts when using asyncio.wait_for() in Python
速率限制
Explain how to use asyncio.Semaphore to rate limit concurrent API calls in Python
生產者-消費者
Show me an example of the producer-consumer pattern using asyncio.Queue for processing items concurrently

Bewährte Verfahren

  • Always use asyncio.run() as the entry point for async programs (Python 3.7+)
  • Use asyncio.gather() for concurrent execution of independent async operations
  • Implement proper timeout handling with asyncio.wait_for() to prevent hanging operations

Vermeiden

  • Calling async functions without await - this returns a coroutine object instead of executing the function
  • Using blocking operations like time.sleep() or CPU-intensive work directly in async code
  • Mixing synchronous and asynchronous code without proper translation using asyncio.run()

Häufig gestellte Fragen

What Python version is required for asyncio?
Python 3.7+ provides asyncio.run() for simple entry points. Newer versions add features like asyncio.to_thread().
What is the maximum number of concurrent tasks?
The event loop can handle thousands of tasks. Use semaphores to limit actual concurrency based on system resources.
Can I use asyncio with FastAPI?
Yes, FastAPI is built on Starlette and natively supports async/await patterns for maximum performance.
Does this skill send data to external services?
No. This is a prompt-based skill providing documentation only. No data is sent anywhere.
Why is my async code running slowly?
Common causes include using blocking operations, not awaiting coroutines, or excessive sequential instead of concurrent execution.
How does asyncio compare to threading?
Asyncio uses single-threaded cooperative multitasking, which is more efficient for I/O-bound work than threading.