ipython / ipython/ipykernel

New event loop integration system

Aperta
#1,371 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
734
Fork
412
Merge medio
1g 5h
PR unite (30g)
8

Descrizione

I would like to change our event-loop integration with Trio's [guest mode](https://trio.readthedocs.io/en/stable/reference-lowlevel.html#using-guest-mode-to-run-trio-on-top-of-other-event-loops). Trio's guest mode also works on asyncio thanks to [aioguest](https://github.com/oremanj/aioguest/tree/master/aioguest). For it to work, we just need to have a function that can schedule a callback in the host event-loop in a thread-safe way.
- in asyncio, that would be `loop.call_soon_threadsafe(callback)`,
- in tkinter, that would be `tk.after(0, callback)`.
- Qt supports Trio's guest mode, see [here](https://doc.qt.io/qtforpython-6/examples/example_async_minimal.html).
- ...

For instance, here is how it looks like when the host event-loop is tkinter's:
```py
from tkinter import Tk

from anyio import sleep
from anyioutils import start_guest_run

def run_sync_soon_threadsafe(fn):
tk.after(0, fn)

def done_callback(outcome):
print("done")

async def foo():
for i in range(10):
await sleep(0.1)
print(i)

tk = Tk()
start_guest_run(foo, run_sync_soon_threadsafe=run_sync_soon_threadsafe, done_callback=done_callback)
tk.mainloop()
```
Before calling `tk.mainloop()`, we call `start_guest_run()` which runs `foo` as a task in tkinter's event-loop.

Thoughts?

Guida per i contributori

Apri la guida per i contributori

Direzione di ricerca

No repository file or test is identified in the issue. Start by reading the proposed start_guest_run entry point and the host-loop callback examples for asyncio, tkinter, and Qt; clarify which integration API and supported event loops are in scope before implementation. Done would mean an agreed design and working guest-mode integration.

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

Valutazione

Stack tecnologico
python
Ambito
backend
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Da chiarire
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.