Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wag the dog – i.e. enslave the python mainloop to the GMainContext #10

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

benzea
Copy link

@benzea benzea commented Nov 8, 2020

No description provided.

As it is right now, any python code that runs may modify the timeout
that would be passed into the select() call. As such, we can only run a
single mainloop iteration before the select() call needs to be
restarted.

Also, we cannot use g_source_set_ready_time, because GLib will always
do a full mainloop iteration afterwards to ensure that all sources had a
chance to dispatch.
This is easy to work around though as we can use the prepare callback to
pass the required timeout from python into the GLib main loop code.

Note that with this we end up iterating the main context but we never
actually run a GLib mainloop.

Fixes: jhenstridge#3
Turn things around and rather than iterating the GLib main context from
python iterate the python mainloop from GLib.

In order to do this, we need to be able to calculate the timeout (and
whether anything can be dispatched) from inside the prepare and check
functions of the source.
We can do that easily by looking at the _ready and _schedule attributes
of the loop. Once we have that, we can dispatch everything scheduled by
python by calling _run_once and relying on our select() implementation
to return immediately.
@benzea
Copy link
Author

benzea commented Nov 8, 2020

Weird, the tests work fine locally for me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant