From: Fredrik Tolf Date: Sat, 11 May 2013 23:03:22 +0000 (+0200) Subject: Changed the reader threading model to do callbacks on the main thread. X-Git-Url: http://git.dolda2000.com/gitweb/?a=commitdiff_plain;h=c84f095d9f394707c973a8faeaf1c83f577e8c0f;p=automanga.git Changed the reader threading model to do callbacks on the main thread. --- 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):