[Reportbug-commits] [reportbug] 18/31: gtk2_ui: call GObject constructors in UI thread

Sandro Tosi morph at moszumanska.debian.org
Mon Jan 16 01:36:57 UTC 2017


This is an automated email from the git hooks/post-receive script.

morph pushed a commit to branch master
in repository reportbug.

commit 505f397bf6cbffc2ffe88ac392bfcb51e71704ae
Author: Simon McVittie <smcv at debian.org>
Date:   Sat Jan 14 19:22:51 2017 +0000

    gtk2_ui: call GObject constructors in UI thread
    
    Subclasses of Gtk objects are part of the Gtk API and must therefore
    only be touched from the GLib "default main-context".
    
    This means we have to rearrange initialization so we start the
    main thread before we construct the rest of the objects.
---
 reportbug/ui/gtk2_ui.py | 29 ++++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/reportbug/ui/gtk2_ui.py b/reportbug/ui/gtk2_ui.py
index d4a84ba..fbc4133 100644
--- a/reportbug/ui/gtk2_ui.py
+++ b/reportbug/ui/gtk2_ui.py
@@ -514,6 +514,26 @@ class ReportbugApplication(threading.Thread):
 
         GLib.idle_add(callback)
 
+    def call_in_main_thread(self, func, *args, **kwargs):
+        def callback():
+            try:
+                ret = func(*args, **kwargs)
+            except BaseException as e:
+                self.set_next_value(e)
+            else:
+                self.set_next_value(ret)
+
+            self.put_next_value()
+            return False
+
+        GLib.idle_add(callback)
+        ret = self.get_last_value()
+
+        if isinstance(ret, BaseException):
+            raise ret
+        else:
+            return ret
+
 
 # Connection with reportbug
 # Syncronize "pipe" with reportbug
@@ -1569,7 +1589,7 @@ dialogs = {'yes_no': YesNoDialog,
 
 def create_forwarder(parent, klass):
     def func(*args, **kwargs):
-        op = klass(parent)
+        op = application.call_in_main_thread(klass, parent)
         try:
             args, kwargs = op.sync_pre_operation(*args, **kwargs)
         except SyncReturn as e:
@@ -1624,13 +1644,12 @@ Falling back to 'text' interface."""
     Gtk.Window.set_default_icon_from_file(DEBIAN_LOGO)
 
     application = ReportbugApplication()
-    assistant = ReportbugAssistant(application)
+    application.start()
+    forward_operations(application, dialogs)
 
-    # Forwarders
+    assistant = application.call_in_main_thread(ReportbugAssistant, application)
     forward_operations(assistant, pages)
-    forward_operations(application, dialogs)
 
-    application.start()
     return True
 
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reportbug/reportbug.git



More information about the Reportbug-commits mailing list