[meld] filediff: Delay as much thread and queue handling as possible to idle
- From: Kai Willadsen <kaiw src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [meld] filediff: Delay as much thread and queue handling as possible to idle
- Date: Sat, 8 Oct 2016 21:59:28 +0000 (UTC)
commit 37fa668d2a79c9dfcdaeb6055f1e95dff8383aa7
Author: Kai Willadsen <kai willadsen gmail com>
Date: Sun Mar 1 09:46:14 2015 +1000
filediff: Delay as much thread and queue handling as possible to idle
Because of interactions between the GIL, Python threads and the GObject
main loop, we get very undesirable behaviour on startup where our
threads behave as borderline synchronous code. By putting as much of
this as possible in idle, we make this behaviour somewhat less
pathological.
meld/filediff.py | 15 +++++++++------
1 files changed, 9 insertions(+), 6 deletions(-)
---
diff --git a/meld/filediff.py b/meld/filediff.py
index e1851dd..c3b8cf7 100644
--- a/meld/filediff.py
+++ b/meld/filediff.py
@@ -60,7 +60,6 @@ class MatcherWorker(threading.Thread):
self.tasks = tasks
self.results = results
self.daemon = True
- self.start()
def run(self):
while True:
@@ -100,6 +99,7 @@ class CachedSequenceMatcher(object):
self.thread = MatcherWorker(self.tasks, self.results)
self.task_id = 1
self.queued_matches = {}
+ GLib.idle_add(self.thread.start)
def match(self, text1, textn, cb):
texts = (text1, textn)
@@ -108,11 +108,14 @@ class CachedSequenceMatcher(object):
opcodes = self.cache[texts][0]
GLib.idle_add(lambda: cb(opcodes))
except KeyError:
- self.tasks.put((self.task_id, texts))
- if not bool(self.queued_matches):
- GLib.idle_add(self.check_results)
- self.queued_matches[self.task_id] = (texts, cb)
- self.task_id += 1
+ GLib.idle_add(lambda: self.enqueue_task(texts, cb))
+
+ def enqueue_task(self, texts, cb):
+ if not bool(self.queued_matches):
+ GLib.idle_add(self.check_results)
+ self.queued_matches[self.task_id] = (texts, cb)
+ self.tasks.put((self.task_id, texts))
+ self.task_id += 1
def check_results(self):
try:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]