This adds a simple asyncio event loop integration for GLib that only works on unix.
That said, I think it works really well:
- Supports all python features; after all, it is the python standard selector mainloop
- User can freely choose the GMainContext, setup works for any threads
-
get_event_loop
returns a new loop if the thread has a main context - main context can be set by creating a loop and using
set_event_loop
; but only if there is no default one-
Nested loops are possible, but setup must be done outside of the-> nested loop work theoretically, but asyncio can't deal with itGLibEventLoopPolicy
Only registered withGLibEventLoopPolicy
if a default thread main context is pushed and t henget_event_loop
is runMainloop can also run withoutGLibEventLoopPolicy
being aware of it
-
- Correctly handles child watches (by using the python watcher; GLib child watches must not be used)
TODO:
-
Add more/better integration points -
Overwrite SIGINT for the default main context -
GApplication.run
and similar
-
-
Add tests for GLib async function integration, i.e. test the !158 (closed) part -
Add tests for nested main loopsworks, but python prevents it -
Windows support? Should be reasonably simple now, but different. See below
On windows, we can't really register the events with GLib properly. But we could:
- Subclass
IocpProactor
and have a custom GSource similar to Linux - In
prepare
:- If polling thread is running, we are done; just check if there are events ready
- If polling thread is not running, call
IocpProator._poll
with 0 timeout directly to assess readyness - If not ready, start/poke polling thread
- In polling thread:
- call
IocpProactor._poll
with (almost) infinite timeout - when it returns, wakeup main context
- wait for until being poked again by source
- call
- In check, just handle timeouts and grab event list