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

Commits on Nov 8, 2020

  1. glib_selector: Only ever iterate the mainloop once

    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
    Benjamin Berg committed Nov 8, 2020
    Configuration menu
    Copy the full SHA
    6bf9545 View commit details
    Browse the repository at this point in the history
  2. Let the GSource dispatch python callbacks

    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.
    Benjamin Berg committed Nov 8, 2020
    Configuration menu
    Copy the full SHA
    928bccd View commit details
    Browse the repository at this point in the history
  3. tests: Read pipe test is working now

    Benjamin Berg committed Nov 8, 2020
    Configuration menu
    Copy the full SHA
    3606b6a View commit details
    Browse the repository at this point in the history