jpskill.com
🛠️ 開発・MCP コミュニティ

python-concurrency-performance

Pythonで並行処理を行うコードの設計やレビューで、asyncio、スレッド、マルチプロセッシングの選択、処理キャンセルや締め切りの伝播、処理の集中と負荷制御などを適切に行い、競合状態やデッドロック、処理速度の低下、スレッドやタスクのリークといった問題点を診断・解決するSkill。

📜 元の英語説明(参考)

Use when designing or reviewing concurrent Python code — selecting between asyncio, threads, or multiprocessing; structuring cancellation and deadline propagation; bounding fan-out and backpressure. Also use when diagnosing race conditions, deadlocks, slow throughput, or thread/task leaks under load.

🇯🇵 日本人クリエイター向け解説

一言でいうと

Pythonで並行処理を行うコードの設計やレビューで、asyncio、スレッド、マルチプロセッシングの選択、処理キャンセルや締め切りの伝播、処理の集中と負荷制御などを適切に行い、競合状態やデッドロック、処理速度の低下、スレッドやタスクのリークといった問題点を診断・解決するSkill。

※ jpskill.com 編集部が日本のビジネス現場向けに補足した解説です。Skill本体の挙動とは独立した参考情報です。

⚡ おすすめ: コマンド1行でインストール(60秒)

下記のコマンドをコピーしてターミナル(Mac/Linux)または PowerShell(Windows)に貼り付けてください。 ダウンロード → 解凍 → 配置まで全自動。

🍎 Mac / 🐧 Linux
mkdir -p ~/.claude/skills && cd ~/.claude/skills && curl -L -o python-concurrency-performance.zip https://jpskill.com/download/10633.zip && unzip -o python-concurrency-performance.zip && rm python-concurrency-performance.zip
🪟 Windows (PowerShell)
$d = "$env:USERPROFILE\.claude\skills"; ni -Force -ItemType Directory $d | Out-Null; iwr https://jpskill.com/download/10633.zip -OutFile "$d\python-concurrency-performance.zip"; Expand-Archive "$d\python-concurrency-performance.zip" -DestinationPath $d -Force; ri "$d\python-concurrency-performance.zip"

完了後、Claude Code を再起動 → 普通に「動画プロンプト作って」のように話しかけるだけで自動発動します。

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して python-concurrency-performance.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → python-concurrency-performance フォルダができる
  3. 3. そのフォルダを C:\Users\あなたの名前\.claude\skills\(Win)または ~/.claude/skills/(Mac)へ移動
  4. 4. Claude Code を再起動

⚠️ ダウンロード・利用は自己責任でお願いします。当サイトは内容・動作・安全性について責任を負いません。

🎯 このSkillでできること

下記の説明文を読むと、このSkillがあなたに何をしてくれるかが分かります。Claudeにこの分野の依頼をすると、自動で発動します。

📦 インストール方法 (3ステップ)

  1. 1. 上の「ダウンロード」ボタンを押して .skill ファイルを取得
  2. 2. ファイル名の拡張子を .skill から .zip に変えて展開(macは自動展開可)
  3. 3. 展開してできたフォルダを、ホームフォルダの .claude/skills/ に置く
    • · macOS / Linux: ~/.claude/skills/
    • · Windows: %USERPROFILE%\.claude\skills\

Claude Code を再起動すれば完了。「このSkillを使って…」と話しかけなくても、関連する依頼で自動的に呼び出されます。

詳しい使い方ガイドを見る →
最終更新
2026-05-18
取得日時
2026-05-18
同梱ファイル
1

📖 Skill本文(日本語訳)

※ 原文(英語/中国語)を Gemini で日本語化したものです。Claude 自身は原文を読みます。誤訳がある場合は原文をご確認ください。

Python の並行性とパフォーマンス

概要

正しい並行処理は、開発者の好みに合わせるのではなく、ワークロードにモデルを適合させることから始まります。 このスキルは、モデル選択、キャンセル/デッドラインの動作、およびライフサイクルセーフティのデフォルトをエンコードし、暗黙的なマジックよりも明示的な制御を優先します。

これらの推奨事項を推奨されるデフォルトとして扱ってください。 プロジェクトの制約により逸脱が必要な場合は、トレードオフと補償的な制御を明示してください。

どのような時に使うか

  • asynciothreadingmultiprocessing、または concurrent.futures の選択
  • 非同期呼び出しチェーンを介したデッドラインまたはキャンセルの伝播
  • ファンアウト、バックプレッシャー、またはセマフォで保護された並行性の制限
  • 競合状態、デッドロック、または優先順位の逆転の診断
  • 最適化前後のスループットボトルネックのプロファイリング
  • シャットダウンまたはライフサイクルの移行時にタスクまたはスレッドのリークがないことの検証

どのような時に使わないか

  • NumPy/C 拡張機能でより適切に処理される純粋な CPU バウンドの数値計算
  • 並行 I/O のないシングルスレッドのスクリプト処理
  • 分散システム連携 (代わりにワークフロー/オーケストレーションスキルを使用)

クイックリファレンス

  • ワークロードプロファイルによって並行モデルを選択します (I/O バウンド → asyncio/threads; CPU バウンド → multiprocessing)。
  • キャンセルとクリーンアップを明示的に保ちます。ガベージコレクションに依存してリソースを閉じないでください。
  • セマフォまたはキュー制限を使用してファンアウトとバックプレッシャーを制限します。無制限の生成は OOM を招きます。
  • 最適化する前に測定し、変更を加えるたびに再測定して改善を確認します。
  • ライフサイクルに依存する変更 (起動、シャットダウン、再接続) でタスク/スレッドのリークがないことを確認します。

よくある間違い

  • I/O バウンドの作業にスレッドをデフォルトで使用するasyncio はネットワーク I/O のスレッドセーフティバグを完全に回避します。スレッドは、何のメリットもなく同期のオーバーヘッドを追加します。
  • キャンセルの伝播を無視する — キャンセルされた親が子をキャンセルしない場合、タスクがリークし、接続が開いたままになります。
  • 無制限の gather / submit 呼び出し — セマフォまたは制限された executor なしで数千のタスクを生成すると、イベントループが枯渇するか、OS スレッドが使い果たされます。
  • プロファイリングなしで最適化する — ボトルネックを推測すると、間違った問題を解決する複雑なコードにつながります。常に最初にプロファイルしてください。
  • シャットダウンの検証の欠落 — クリーンなシャットダウンをアサートしないテストは、負荷がかかった本番環境でのみ表面化する遅いリソースリークを隠蔽します。

スコープに関する注意

  • これらの推奨事項を、一般的なケースに対する推奨されるデフォルトとして扱い、普遍的なルールとして扱わないでください。
  • デフォルトがプロジェクトの制約と矛盾する場合、または結果を悪化させる場合は、より適切な代替案を提案し、このケースでそれがより優れている理由を説明してください。
  • 逸脱する場合は、トレードオフと補償的な制御 (テスト、可観測性、移行、ロールバック) を明示してください。

呼び出しに関する注意

  • このスキルが名前 python-concurrency-performance で呼び出されていることをユーザーに通知します。

参考文献

  • references/concurrency-models.md
  • references/deadlines-cancellation-lifecycle.md
  • references/leak-detection.md
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Python Concurrency and Performance

Overview

Correct concurrency starts with matching the model to the workload, not the developer's preference. This skill encodes defaults for model selection, cancellation/deadline behavior, and lifecycle safety—prioritizing explicit control over implicit magic.

Treat these recommendations as preferred defaults. When project constraints demand deviation, call out tradeoffs and compensating controls.

When to Use

  • Selecting between asyncio, threading, multiprocessing, or concurrent.futures
  • Propagating deadlines or cancellation through async call chains
  • Bounding fan-out, backpressure, or semaphore-guarded concurrency
  • Diagnosing race conditions, deadlocks, or priority inversion
  • Profiling throughput bottlenecks before and after optimization
  • Verifying no task or thread leaks on shutdown or lifecycle transitions

When NOT to Use

  • Pure CPU-bound numeric work better served by NumPy/C extensions
  • Single-threaded scripting with no concurrent I/O
  • Distributed systems coordination (use a workflow/orchestration skill instead)

Quick Reference

  • Choose the concurrency model by workload profile (I/O-bound → asyncio/threads; CPU-bound → multiprocessing).
  • Keep cancellation and cleanup explicit—never rely on garbage collection to close resources.
  • Bound fan-out and backpressure with semaphores or queue limits; unbounded spawning invites OOM.
  • Measure before optimizing; re-measure after every change to confirm the win.
  • Verify no task/thread leaks on any lifecycle-sensitive change (startup, shutdown, reconnect).

Common Mistakes

  • Defaulting to threads for I/O-bound workasyncio avoids thread-safety bugs entirely for network I/O; threads add synchronization overhead for no gain.
  • Ignoring cancellation propagation — a cancelled parent that doesn't cancel children leaks tasks and holds connections open.
  • Unbounded gather / submit calls — spawning thousands of tasks without a semaphore or bounded executor starves the event loop or exhausts OS threads.
  • Optimizing without profiling — guessing at bottlenecks leads to complex code that solves the wrong problem; always profile first.
  • Missing shutdown verification — tests that don't assert clean shutdown mask slow resource leaks that surface only in production under load.

Scope Note

  • Treat these recommendations as preferred defaults for common cases, not universal rules.
  • If a default conflicts with project constraints or worsens the outcome, suggest a better-fit alternative and explain why it is better for this case.
  • When deviating, call out tradeoffs and compensating controls (tests, observability, migration, rollback).

Invocation Notice

  • Inform the user when this skill is being invoked by name: python-concurrency-performance.

References

  • references/concurrency-models.md
  • references/deadlines-cancellation-lifecycle.md
  • references/leak-detection.md