From f4ebbf563c4e703d1e26fc48380d4813a4416b02 Mon Sep 17 00:00:00 2001 From: Daniel Drake Date: Mon, 10 Dec 2012 18:02:17 +0000 Subject: Call into bundle registry from main thread (#12272) When installing/updating bundles, bundleregistry will fire the 'bundle-added' signal directly. This triggers signal handlers in Sugar's favoritesview and activitylist classes which are not thread-safe. Triggering the signal in this way was resulting in weird UI hangs after the updater has been run. Avoid these issues by calling into the bundle registry only from the main thread. --- diff --git a/src/view.py b/src/view.py index efc8de6..76708d5 100755 --- a/src/view.py +++ b/src/view.py @@ -13,10 +13,11 @@ from gi.repository import GLib from gi.repository import GObject GLib.threads_init() +import logging import gettext import os import re -from threading import Thread +from threading import Thread, Event import gettext _ = lambda msg: gettext.dgettext('sugar-update-control', msg) @@ -524,6 +525,11 @@ class ActivityUpdater(SectionView): # and start refreshing. self.refresh_cb(None, None) + def install_cb(self, registry, bundle, event): + bundle.install_or_upgrade(registry) + event.set() + return False + def download_cb(self, widget, event, data=None): """Invoked when the 'ok' button is clicked.""" from sugar3.bundle.activitybundle import ActivityBundle @@ -539,6 +545,7 @@ class ActivityUpdater(SectionView): # get activity registry from jarabe.model.bundleregistry import get_registry registry = get_registry() # requires a dbus-registered main loop + install_event = Event() # progress bar bookkeeping. counts = [0, self.activity_list.updates_selected(), 0] def p(n, extra, icon): @@ -558,8 +565,11 @@ class ActivityUpdater(SectionView): b = actutils.BundleHelper(f) p(counts[2], _('Installing %s...') % b.get_name(), _svg2pixbuf(b.get_icon_data())) - b.install_or_upgrade(registry) + install_event.clear() + GLib.idle_add(self.install_cb, registry, b, install_event) + install_event.wait() except: + logging.exception("Failed to install bundle") pass # XXX: use alert to indicate install failure. if os.path.exists(f): os.unlink(f) -- cgit v0.9.1