技能 async-python-patterns
📊 69 充足
1
下載技能 ZIP
2
在 Claude 中上傳
前往 設定 → 功能 → 技能 → 上傳技能
3
開啟並開始使用
測試它
正在使用「async-python-patterns」。 展示如何同時帶超時控制地獲取多個 URL
預期結果:
- 使用 asyncio.gather() 搭配 asyncio.wait_for() 進行超時控制
- 建立帶有連線池的 aiohttp ClientSession
- 優雅地處理成功回應和超時情況
- 傳回帶有狀態碼和錯誤資訊的結果
正在使用「async-python-patterns」。 如何為 API 呼叫實作速率限制器
預期結果:
- 使用 asyncio.Semaphore 限制並發請求
- 搭配非同步上下文管理員模式應用 Semaphore
- 根據 API 限制設定適當的 max_concurrent 值
- 結合重試邏輯以提升穩健性
正在使用「async-python-patterns」。 撰寫非同步 Python 程式碼時常見的錯誤有哪些
預期結果:
- 忘記 await 協程 - 它們會傳回協程物件,而非結果
- 使用 time.sleep() 而非 asyncio.sleep() - 會阻塞事件循環
- 未使用 try/except CancelledError 處理任務取消
- 混合同步和非同步程式碼而未適當包裝
安全審計
安全v4 • 1/17/2026
Documentation-only skill containing Python async programming patterns. Static analyzer flagged 77 findings, all confirmed as false positives. Markdown code fences were misidentified as shell backticks. Documentation text was misidentified as cryptographic algorithms. Example URLs are standard placeholders. No executable code, network access, or security risks exist.
2
已掃描檔案
869
分析行數
2
發現項
4
審計總數
風險因素
🌐 網路存取 (10)
⚙️ 外部命令 (48)
SKILL.md:33 SKILL.md:36-40 SKILL.md:40-49 SKILL.md:49-52 SKILL.md:52-56 SKILL.md:56-66 SKILL.md:66-72 SKILL.md:72-85 SKILL.md:85-89 SKILL.md:89-110 SKILL.md:110-114 SKILL.md:114-140 SKILL.md:140-144 SKILL.md:144-176 SKILL.md:176-180 SKILL.md:180-197 SKILL.md:197-203 SKILL.md:203-233 SKILL.md:233-237 SKILL.md:237-267 SKILL.md:267-271 SKILL.md:271-323 SKILL.md:323-327 SKILL.md:327-351 SKILL.md:351-355 SKILL.md:355-394 SKILL.md:394-400 SKILL.md:400-437 SKILL.md:437-441 SKILL.md:441-479 SKILL.md:479-483 SKILL.md:483-539 SKILL.md:539-545 SKILL.md:545-557 SKILL.md:557-561 SKILL.md:561-574 SKILL.md:574-578 SKILL.md:578-601 SKILL.md:601-607 SKILL.md:607-613 SKILL.md:613-617 SKILL.md:617-626 SKILL.md:626-630 SKILL.md:630-641 SKILL.md:641-645 SKILL.md:645-653 SKILL.md:653-657 SKILL.md:657-673
審計者: claude 查看審計歷史 →
品質評分
38
架構
100
可維護性
85
內容
20
社群
100
安全
87
規範符合性
你能建構什麼
建構非同步 Web API
使用適當的非同步模式建立 FastAPI 和 aiohttp 應用程式,以處理並發請求
並發資料處理
實作資料庫查詢、檔案處理和 API 呼叫的平行 I/O 操作
非同步自動化腳本
撰寫能夠並發處理多個網路操作的高效自動化工具
試試這些提示
基礎非同步模式
展示如何建立一個簡單的非同步函式,使用 asyncio.sleep() 來模擬網路延遲
並發請求
示範如何使用 asyncio.gather() 搭配適當的錯誤處理來並發發送 10 個 HTTP 請求
生產者-消費者佇列
使用 asyncio.Queue 建立生產者-消費者模式,處理 100 個項目並配備 5 個工作執行緒
WebSocket 伺服器
設計一個能夠處理多個用戶端並向所有連線使用者廣播訊息的非同步 WebSocket 伺服器
最佳實務
- 始終使用 asyncio.run() 作為非同步應用程式的進入點
- 在非同步函式中使用適當的 try/except 區塊進行錯誤處理
- 使用連線池和 Semaphore 限制並發操作
避免
- 永遠不要在非同步程式碼中使用 time.sleep() - 請使用 asyncio.sleep()
- 不要忘記 await 協程,否則它們將不會執行
- 避免將阻塞性 I/O 操作與非同步程式碼混合使用
常見問題
哪些 Python 版本支援 asyncio?
Python 3.4+ 支援 asyncio,但建議使用 Python 3.7+ 以獲得 async/await 語法和 asyncio.run()
何時應該使用 async 而非執行緒?
對 I/O-bound 操作使用 async,對會阻塞事件循環的 CPU-bound 任務使用執行緒
我可以和 Django 一起使用 async 嗎?
Django 3.0+ 支援非同步視圖,但使用 Django 4.1+ 可獲得完整的非同步 ORM 支援
如何偵錯非同步程式碼?
使用 asyncio 偵錯模式、適當的日誌記錄,以及像 aiomonitor 這樣的工具來進行生產環境偵錯
create_task 和 gather 之間有什麼區別?
create_task() 排程單個協程,而 gather() 則會並發執行多個協程並等待全部完成
這個技能是否與 Jupyter 筆記本相容?
可以,但在筆記本中使用 asyncio.run() 時要小心 - 考慮使用 nest_asyncio 處理嵌套事件循環
開發者詳情
作者
wshobson授權
MIT
儲存庫
https://github.com/wshobson/agents/tree/main/plugins/python-development/skills/async-python-patterns引用
main
檔案結構
📄 SKILL.md