printing from custom loop

Abierto
#1,083 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
38/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
jupyter, python
Área
backend, tooling

Línea de trabajo

Empieza leyendo ipykernel/eventloops.py junto con la llamada a cb() del bucle personalizado y el manejo de kernel.shell_stream.flush(limit=1). Reproduce el flujo de %gui imgui en la Jupyter web UI o en IntelliJ IDEA y verifica después que print('123') de imgui_app() aparece antes de que se cierre la aplicación.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

I made a custom event loop for Dear ImGui. Everything works fine, except i can not find a way to produce any output from within the loop where UI code runs. This is the loop:

from ipykernel.eventloops import register_integration


@register_integration('imgui')
def loop_imgui(kernel):
    import imgui
    app = None
    try:
        while not kernel.shell.exit_now:
            if len(imgui._ipython_callbacks) > 0:
                title, cb = imgui._ipython_callbacks[0]
                if app is None:
                    app = imgui.DearImGuiApp(title)

                do_continue = False
                if app.begin_frame():
                    try:
                        do_continue = cb()
                    finally:
                        app.end_frame()

                if not do_continue:
                    app.close()
                    app = None
                    del imgui._ipython_callbacks[0]

            if kernel.shell_stream.flush(limit=1):
                break
    except Exception as e:
        kernel.log.exception(e)
    finally:
        imgui._ipython_callbacks = []
        if app is not None:
            app.close()
            app = None


@loop_imgui.exit
def loop_imgui_exit(kernel):
    pass


def load_ipython_extension(ipython):
    pass


def unload_ipython_extension(ipython):
    pass

I use it as follows:

%load_ext imgui_loop
%gui imgui

import imgui

@imgui.ipython_window('Charts')
def imgui_app():
    print('123')
    return False

Im sorry about this code not being testable as i do not have all parts available on github.. But basically imgui_app() gets called on the line do_continue = cb() in the loop code. It should print '123' and then imgui app gets closed. I do not see any text printed though, documentation mentions nothing about it either and ipykernel/eventloops.py does imply printing should just work..? But somehow it does not. I tested it from IntelliJ IDEA as well as from Jupyter web UI - result is same. Other than this, imgui UI works just fine. Any ideas what i could be missing?

Thanks 🙏

Lenguaje dominante
Python
Estrellas
734
Forks
411
Merge medio
1 d 2 h
PR fusionados (30 d)
9

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ipython/ipykernel

Todos los issues de ipython/ipykernel

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.