Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

printing from custom loop

Aperta
#1,083 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
38/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
jupyter, python
Ambito
backend, tooling

Direzione di ricerca

Inizia leggendo ipykernel/eventloops.py insieme alla chiamata a cb() del loop personalizzato e alla gestione di kernel.shell_stream.flush(limit=1). Riproduci il flusso %gui imgui nella Jupyter web UI o in IntelliJ IDEA, quindi verifica che print('123') da imgui_app() venga visualizzato prima della chiusura dell'app.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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 🙏

Lingua principale
Python
Stelle
734
Fork
411
Merge medio
1g 2h
PR unite (30g)
9

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ipython/ipykernel

Tutte le issue di ipython/ipykernel

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.