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

python-notebooks-async

Jupyter Notebookやセル形式の環境で、asyncioを使ったコードの実行やレビュー、イベントループの管理、タスクの調整、互換性対応など、非同期処理に関する問題を解決し、効率的な開発を支援するSkill。

📜 元の英語説明(参考)

Use when writing or reviewing asyncio code in Jupyter notebooks or '#%%' cell workflows — structuring event-loop ownership, orchestrating async tasks, or choosing compatibility strategies. Also use when hitting RuntimeError: This event loop is already running, asyncio.run() failures in cells, or tasks silently never completing.

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

一言でいうと

Jupyter Notebookやセル形式の環境で、asyncioを使ったコードの実行やレビュー、イベントループの管理、タスクの調整、互換性対応など、非同期処理に関する問題を解決し、効率的な開発を支援するSkill。

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

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

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

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

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

💾 手動でダウンロードしたい(コマンドが難しい人向け)
  1. 1. 下の青いボタンを押して python-notebooks-async.zip をダウンロード
  2. 2. ZIPファイルをダブルクリックで解凍 → python-notebooks-async フォルダができる
  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 Notebooks Async

概要

Notebook カーネルはイベントループを所有しています。async コードは、その所有権と競合するのではなく、協調する必要があります。 このスキルでは、オーケストレーションパターン、トップレベルの await、および .ipynb#%% のワークフローの互換性の制約について説明します。

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

いつ使うか

  • asyncio.run() が notebook セル内で RuntimeError を発生させる場合。
  • Jupyter で async ライブラリを混在させる際のイベントループの競合。
  • async スクリプトを notebook ワークフローに移植する場合。
  • IPython カーネルで同時実行タスク (gather, TaskGroup) をオーケストレーションする場合。
  • notebook/モジュール境界を越えて再利用可能な async ロジックを配置する場所を決定する場合。

いつ使わないか

  • notebook が関与しない純粋なスクリプトまたはサービスコード — python-concurrency-performance を参照してください。
  • async の必要がない同期 notebook ワークフロー。
  • notebook コンテキスト外の一般的な asyncio API 設計 — python-runtime-operations を参照してください。

クイックリファレンス

  • notebook カーネルをループ所有環境として扱い、競合するループを絶対に作成しないでください。
  • notebook セルでは asyncio.run() の代わりにトップレベルの await を使用してください。
  • asyncio.gather() または asyncio.TaskGroup で同時実行作業をオーケストレーションしてください。
  • 再利用可能な async ロジックは、通常の .py モジュールに保持し、notebook にインポートしてください。
  • nest_asyncio は、デフォルトではなく、制約された互換性のフォールバックとしてのみ使用してください。
  • fire-and-forget タスクは避けてください — 常に await するか、結果を明示的に収集してください。

よくある間違い

  • notebook セルで asyncio.run() を呼び出すこと。 カーネルはすでにループを実行しています。asyncio.run() は 2 番目のループを開始しようとし、RuntimeError を発生させます。 代わりに await を直接使用してください。
  • デフォルトで nest_asyncio をグローバルに適用すること。 再入可能な呼び出しを許可するようにループにパッチを適用しますが、設計上の問題を隠蔽し、微妙な並行性バグを隠す可能性があります。 レガシー互換性のために予約してください。
  • モジュールではなく、セル内で async ヘルパーをインラインで定義すること。 インライン定義はカーネルの再起動時に失われ、notebook の外部でテストできません。 .py ファイルに抽出してください。
  • 返されたタスクまたはコルーチンを無視すること。 await なしで async 関数を呼び出すと、実行されないコルーチンオブジェクトが暗黙的に生成され、結果が下流で欠落するまでエラーは発生しません。
  • 同じセル内でブロッキング I/O と async を混在させること。 requests.get() のような同期呼び出しはイベントループをブロックし、同時実行タスクを停止させます。 aiohttphttpx、または asyncio.to_thread() を使用してください。

スコープに関する注意

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

呼び出しに関する注意

  • このスキルが名前で呼び出されている場合は、ユーザーに通知してください: python-design-modularity

参考文献

  • references/notebooks-async.md
📜 原文 SKILL.md(Claudeが読む英語/中国語)を展開

Python Notebooks Async

Overview

Notebook kernels own the event loop; async code must cooperate with that ownership rather than fight it. This skill covers orchestration patterns, top-level await, and compatibility constraints for .ipynb and #%% workflows.

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

When to Use

  • asyncio.run() raises RuntimeError inside a notebook cell.
  • Event-loop conflicts when mixing async libraries in Jupyter.
  • Porting async scripts into notebook workflows.
  • Orchestrating concurrent tasks (gather, TaskGroup) in IPython kernels.
  • Deciding where to place reusable async logic across notebook/module boundaries.

When NOT to Use

  • Pure script or service code with no notebook involvement — see python-concurrency-performance.
  • Synchronous notebook workflows with no async needs.
  • General asyncio API design outside notebook contexts — see python-runtime-operations.

Quick Reference

  • Treat notebook kernels as loop-owned environments; never create a competing loop.
  • Use top-level await instead of asyncio.run() in notebook cells.
  • Orchestrate concurrent work with asyncio.gather() or asyncio.TaskGroup.
  • Keep reusable async logic in regular .py modules, imported into notebooks.
  • Use nest_asyncio only as a constrained compatibility fallback, not a default.
  • Avoid fire-and-forget tasks — always await or collect results explicitly.

Common Mistakes

  • Calling asyncio.run() in a notebook cell. The kernel already runs a loop; asyncio.run() tries to start a second one and raises RuntimeError. Use await directly instead.
  • Applying nest_asyncio globally by default. It patches the loop to allow reentrant calls but masks design problems and can hide subtle concurrency bugs. Reserve it for legacy compatibility.
  • Defining async helpers inline in cells instead of modules. Inline definitions are lost on kernel restart and cannot be tested outside the notebook. Extract to .py files.
  • Ignoring returned tasks or coroutines. Calling an async function without await silently produces a never-executed coroutine object, with no error until results are missing downstream.
  • Mixing blocking I/O with async in the same cell. Synchronous calls like requests.get() block the event loop, starving concurrent tasks. Use aiohttp, httpx, or asyncio.to_thread().

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-design-modularity.

References

  • references/notebooks-async.md