Fork me on GitHub

GTask by Christian Hergert

Asynchronous and Callback-based execution for GObject

About

GTask is a mini-framework to simplify asynchronous and concurrent programming with C and GObject. GTask makes event driven programming easier whether you are in C or in a higher level language such as Python.

Documentation

I have an overview to GTask as well as the API reference available. I would suggest you start with the overview.

Dependencies

You will need the following packages and their development headers.

Core Library
glib-2.0   >= 2.16
thread-2.0 >= 2.16
object-2.0 >= 2.16
Vala Bindings

Vala bindings will be installed if the valac executable is found.

Python Bindings

For python bindings, you need pygtk and its development package (for pygtk-codegen-2.0).

Examples

Rss Parser
#!/usr/bin/env python

import glib
import gtask
import rss

def parse(data):
    p = rss.Parser()
    p.load_from_data(data, len(data))
    return p.get_document().get_items()

def display(items):
    for item in items:
        print item.props.title

url = 'http://audidude.com/blog/?feed=rss2'

loop = glib.MainLoop()

# get the content asynchronously
task = gtask.Task(lambda: urllib.urlopen(url).read())

# parse the content, but again, asynchronously
task.add_callback(lambda d: gtask.Task(parse, d))

# display the content to the console
task.add_callback(display)

# quit the application
task.add_both(lambda _: loop.quit(),
              lambda _: loop.quit())

loop.run()

License

GTask is licensed under the terms of the LGPL-2.

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Library General Public License for more details.

You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the:

  Free Software Foundation, Inc.,
  51 Franklin Street, Fifth Floor, Boston MA 02110-1301 USA

Authors

Christian Hergert <chris dronelabs com>

Contact

Christian Hergert <chris dronelabs com>

Download

You can download this project in either zip or tar formats.

You can also clone the project with Git by running:

$ git clone git://github.com/chergert/gtask