ipython / ipython/ipykernel

GUI integration in Jupyter notebook with do_one_iteration does not work

Offen
#460 1 Kommentar 3 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Python
Sterne
734
Forks
412
Ø Merge
1 T. 5 Std.
Gemergte PRs (30 T.)
8

Beschreibung

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.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.