I'm writing a Python + GObject app that needs to read a non-trivial amount of data from disk upon start. The data is read synchronously and it takes about 10 seconds to finish the read operation, during which time the loading of the UI is delayed.
I'd like to run the task asynchronously, and get a notification when it's ready, without blocking the UI, more or less like:
def take_ages(): read_a_huge_file_from_disk() def on_finished_long_task(): print "Finished!" run_long_task(task=take_ages, callback=on_finished_long_task) load_the_UI_without_blocking_on_long_task()
I've used GTask in the past for this sort of thing, but I'm concerned that its code hasn't been touched in 3 years, let alone been ported to GObject Introspection. Most importantly, it's no longer available in Ubuntu 12.04. So I'm looking for an easy way to run tasks asynchronously, either in a standard Python way or in a GObject/GTK+ standard way.
Edit: here's some code with an example of what I'm trying to do. I've tried
python-defer as suggested in the comments, but I could not manage to run the long task asynchronously and let the UI load without having to wait for it to finish. Browse the test code.
Is there an easy and widely used way of running asynchronous tasks and get notified when they're finished?