def schedule_in_main_thread(func, *args):
    """Schedules a function to be run in the main thread.
    It will as soon as the mainloop schedules it, normally
    it happens within a few ms.
    """
    from gi.repository import GLib
    GLib.idle_add(func, *args)
