From c84f095d9f394707c973a8faeaf1c83f577e8c0f Mon Sep 17 00:00:00 2001 From: Fredrik Tolf Date: Sun, 12 May 2013 01:03:22 +0200 Subject: [PATCH] Changed the reader threading model to do callbacks on the main thread. --- manga/reader.py | 43 +++++++++++++++++-------------------------- 1 file changed, 17 insertions(+), 26 deletions(-) diff --git a/manga/reader.py b/manga/reader.py index 6f98bee..37972b4 100644 --- a/manga/reader.py +++ b/manga/reader.py @@ -23,23 +23,18 @@ class future(threading.Thread): try: val = self.value() except Exception as e: - with gtk.gdk.lock: - try: - self._exc = e - for cb in self._notlist: - cb() - self._notlist = [] - finally: - gtk.gdk.flush() + self._exc = e + gobject.idle_add(self._callcbs, True) else: - with gtk.gdk.lock: - try: - self._val = [val] - for cb in self._notlist: - cb() - self._notlist = [] - finally: - gtk.gdk.flush() + self._val = [val] + gobject.idle_add(self._callcbs, True) + + def _callcbs(self, final): + nls = [] + for cb in self._notlist: + if cb(): + nls.append(cb) + self._notlist = [] if final else nls # Caller must hold GDK lock def notify(self, cb): @@ -50,15 +45,7 @@ class future(threading.Thread): cb() def progcb(self): - with gtk.gdk.lock: - try: - nls = [] - for cb in self._notlist: - if cb(): - nls.append(cb) - self._notlist = nls - finally: - gtk.gdk.flush() + gobject.idle_add(self._callcbs, False) @property def val(self): @@ -100,7 +87,11 @@ class imgload(future): buf.extend(read) self.progcb() self.st = None - return gtk.gdk.pixbuf_new_from_stream(gio.memory_input_stream_new_from_data(str(buf))) + with gtk.gdk.lock: + try: + return gtk.gdk.pixbuf_new_from_stream(gio.memory_input_stream_new_from_data(str(buf))) + finally: + gtk.gdk.flush() @property def prog(self): -- 2.11.0