Python Gio.Task binding missing

I can’t find GTask interface for Python in either Fedora 31 builds and in flatpak org.gnome.Platform builds. This makes building async based application really hard to do. Am I missing something here? Or it is just a bad state of python bindings? Should I create bug report for this issue?

I want to use Gio.Task for async calls with Python and Gtk Widgets.

Regards Ondrej

You haven’t told us how you’re trying to use GTask.

Anyway, GTask is part of GIO, so you need something like this (WARNING: untested code):

class Foo (GObject.Object):
    def __init__(self):

    def bar(self, question):
        @question: the question to ask

        Computes the answer synchronously.
        # long running computation
        return 42

    def bar_async(self, question, cancellable, callback):
        @question: the question to ask
        @cancellable: a Gio.Cancellable, or None
        @callback: (callable): a function to be called when the result is
          available; takes two arguments: callback(self, result)

        Runs bar() asynchronously.
        def bar_in_thread(task, self, data, cancellable):
            res ='question'))

        # Pass the arguments for bar as data to the task
        task_data = { 'question': question }

        task =, cancellable, callback)

    def bar_finish(self, result):
        To be called in the callback passed to bar_async(); result
        is the asynchronous result of the callback
        return result.propagate_int()
1 Like

Thanks! What a bad question. Maybe it will at least help some Googler. Thanks :heart:

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.