ipython / ipython/ipykernel

GUI integration in Jupyter notebook with do_one_iteration does not work

オープン
#460 コメント 1 件 リアクション 3 件 担当者 0 名 GitHub で見る
主要言語
Python
スター
734
フォーク
412
平均マージ
1日 5時間
マージ済み PR(30日)
8

説明

Kernel: Python 3.7.4 (default, Aug 9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]
IPython version: 7.9.0
Jupyter notebook and Jupyter lab show the same behaviour.

I am trying to set up a GUI integration as given in the [documentation](https://ipython.readthedocs.io/en/stable/config/eventloops.html) for notebooks. Here is a minimal example:

```
@register_integration('minimalexample')
def loop_tk(kernel):
"""Start a kernel with the Tk event loop."""
from tkinter import Tk

# Tk uses milliseconds
poll_interval = int(1000*kernel._poll_interval)
# For Tkinter, we create a Tk object and call its withdraw method.
class Timer(object):
def __init__(self, func):
self.app = Tk()
self.app.withdraw()
self.func = func

def on_timer(self):
self.func()
self.app.after(poll_interval, self.on_timer)

def start(self):
self.on_timer() # Call it once to get things going.
self.app.mainloop()

kernel.timer = Timer(kernel.do_one_iteration)
kernel.timer.start()
```

However, the following behaviour occurs:
After `%gui minimalexample`, the first cell execution request is not executed (it shows a star in the cell status). Every consecutive request works, until a request that triggers an error is executed. Every cell execution request that happens afterwards is not successful, the star is shortly shown, no output. I see also that the event loop integration in the source code is solved differently now, by executing the event loop that should be integrated and falling back to the original event loop on zmq socket activity, but I haven't found a possibility in my case to exit the event loop without tearing down the complete GUI (I am integrating WinForms via PythonNet). Is the way of integration as shown in the documentation deprecated? If not, I would say this is a bug, if yes, the documentation should be updated.

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

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

評価

この issue はまだ評価されていません。

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

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