Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

Async widget methods deadlock due to on_msg not being called

オープン
#646 コメント 11 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
5/5
見積もり時間
1週間以上
初心者へのやさしさ
25/100
issue の種類
バグ
明瞭さ
説明が足りない
活発さ
停滞
技術スタック
jupyter, jupyter-notebook, python
領域
api, backend

調査の方向性

まず、widget の send/on_msg await ケースを再現し、その動作を IPython issue 12786 および ipykernel PR 589 と比較します。完了条件は、セルが await 中でも on_msg コールバックがレスポンスを処理でき、デッドロックしたり 2 つ目のセルを必要としたりしないことです。

索引モデルが issue の本文から書いたものです。

説明

We are developing a Jupyter widget which makes it possible to embed interactive Unfolded maps into notebooks:

image

Our widget is embedded via an iframe and so the communications with the JavaScript side are asynchronous. Some of the functions we want to add to the widget need to return data asynchronously. To communicate between Jupyter and JS we are using widget's send and on_msg methods. Our methods return futures. It works fine - the messages are being sent and received, but only if we do it in two steps:

image

When we are trying to use await so that we can have the results and do something with them within one cell, the execution is blocked forever:

image

We tried to investigate the cause. It turns out that the callback we register with widget.on_msg only gets called once the execution of the cell is finished. Hence, if we wait until we obtain the result of the calculation within the same cell where the method was called, we end up in a deadlock.

So far we've had no success in finding a workaround, despite trying many things. For instance, here we run the communication in a separate thread and wait until the query response is added to a blocking queue:
image

Calling the above function fails (after the 2 seconds timeout) with an error saying that the queue is empty:
image
And we don't see the _receive function being called.

However, if we check the queue immediately after getting this error, we can see that the queue is not empty - the response was added to it, apparently, just after the error caused the cell execution to be cancelled:
image

It might be the same issue as this one: https://github.com/ipython/ipython/issues/12786
but I am not completely sure. I tried installing and running the kernel with the fix from this PR, but I was getting errors related to traitlet messaging when trying to instantiate our widget.

主要言語
Python
スター
734
フォーク
411
平均マージ
1日 2時間
マージ済み PR(30日)
9

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

ipython/ipykernel のほかの issue

ipython/ipykernel の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。