[Reportbug-commits] [reportbug] 21/31: gtk2_ui: lazily import gtkspellcheck from the UI thread

Sandro Tosi morph at moszumanska.debian.org
Mon Jan 16 01:36:58 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 77a3dae38776644a13f36fa4aa46856f327a8fc6
Author: Simon McVittie <smcv at debian.org>
Date:   Sat Jan 14 23:48:12 2017 +0000

    gtk2_ui: lazily import gtkspellcheck from the UI thread
    
    If we import it globally (in the reportbug thread), we get:
    
    sqlite3.ProgrammingError: SQLite objects created in a thread can only be
    used in that same thread. The object was created in thread id
    <some large number> and this is thread id <some other large number>
---
 reportbug/ui/gtk2_ui.py | 21 ++++++++++++++-------
 1 file changed, 14 insertions(+), 7 deletions(-)

diff --git a/reportbug/ui/gtk2_ui.py b/reportbug/ui/gtk2_ui.py
index c29ec7e..d83b2e3 100644
--- a/reportbug/ui/gtk2_ui.py
+++ b/reportbug/ui/gtk2_ui.py
@@ -47,11 +47,7 @@ except ImportError:
 
 global Vte
 
-try:
-    import gtkspellcheck
-    has_spell = True
-except:
-    has_spell = False
+gtkspellcheck = None
 
 #gtk.set_interactive(0)
 Gdk.threads_init()
@@ -1309,7 +1305,18 @@ class EditorPage(Page):
         self.view = Gtk.TextView()
         self.view.modify_font(Pango.FontDescription("Monospace"))
         self.view.set_wrap_mode(Gtk.WrapMode.WORD)
-        if has_spell:
+
+        # We have to do the import in the UI thread, because it loads a
+        # SQLite database at import time, and the Python SQLite bindings
+        # don't allow transferring a SQLite handle between threads.
+        global gtkspellcheck
+        if gtkspellcheck is None:
+            try:
+                import gtkspellcheck
+            except:
+                gtkspellcheck = NotImplemented
+
+        if gtkspellcheck is not NotImplemented:
             gtkspellcheck.SpellChecker(self.view)
         self.info_buffer = self.view.get_buffer()
         scrolled = create_scrollable(self.view)
@@ -1323,7 +1330,7 @@ class EditorPage(Page):
         expander.add(scrolled)
         vbox.pack_start(expander, False, True, 0)
 
-        if not has_spell:
+        if gtkspellcheck is NotImplemented:
             box = Gtk.EventBox()
             label = Gtk.Label("Please install <b>python-gtkspellcheck</b> to enable spell checking")
             label.set_use_markup(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