ipython / ipython/ipykernel

GUI integration in Jupyter notebook with do_one_iteration does not work

Aberta
#460 1 comentário 3 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Python
Estrelas
734
Forks
412
Merge médio
1d 5h
PRs com merge (30d)
8

Descrição

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.

Guia de contribuição

Abrir o guia de contribuição

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.