ipython / ipython/ipykernel

GUI integration in Jupyter notebook with do_one_iteration does not work

未關閉
#460 1 則留言 3 個 reaction 已指派 0 人 在 GitHub 檢視
主要語言
Python
星號
734
分支
412
平均合併
1 天 5 小時
30 天內合併 PR
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 摘要。