libui.loop — Threading & Event Loop

Two-thread architecture: main thread owns libui, asyncio in background.

libui.loop.invoke_on_main(fn, *args, **kwargs)

Block the calling thread until fn runs on the main UI thread.

Returns the result of fn(*args, **kwargs). If fn raises, the exception is re-raised in the caller.

If already on the main thread, runs fn directly (avoids deadlock).

async libui.loop.invoke_on_main_async(fn, *args, **kwargs)

Await the result of fn running on the main UI thread (non-blocking).

libui.loop.quit() None

Signal the UI event loop to stop.

Safe to call from any thread.

libui.loop.run(coro) None

Run coro with the libui event loop.

This is a synchronous function — the new entry point is simply:

libui.run(main())

Main thread: initialises libui, pumps main_step(wait=True). Background thread: runs asyncio.run(coro).