gtk.gdk.threads_init()
@contextlib.contextmanager def gtk_lock(): gtk.gdk.threads_enter() try: yield finally: gtk.gdk.threads_leave()
with gtk_lock(): # do stuff
def async(func): """ Make a function mainloop friendly. the function will be called at the next mainloop idle state. """ @functools.wraps(func) def new_function(*args, **kwargs): def async_function(): func(*args, **kwargs) return False gobject.idle_add(async_function) return new_function