From df08dd4f538ecae1a4ca97346aa6180205e96f64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luk=C3=A1=C5=A1=20Lalinsk=C3=BD?= Date: Sun, 9 Sep 2007 19:12:58 +0200 Subject: [PATCH] Special thread queue for decoding and fingerpringint, neither FFmeg nor libofa like beeing called from multiple threads. --- picard/musicdns/__init__.py | 6 +++--- picard/tagger.py | 2 +- picard/util/thread.py | 19 ++++++++++++------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/picard/musicdns/__init__.py b/picard/musicdns/__init__.py index f6768b257..0aa6a7466 100644 --- a/picard/musicdns/__init__.py +++ b/picard/musicdns/__init__.py @@ -138,9 +138,9 @@ class OFA(QtCore.QObject): return # calculate fingerprint if ofa is not None: - thread_pool.call(partial(self._calculate_fingerprint, file.filename), - partial(self._lookup_fingerprint, next, file), - QtCore.Qt.LowEventPriority + 1) + thread_pool.ofa_call(partial(self._calculate_fingerprint, file.filename), + partial(self._lookup_fingerprint, next, file), + QtCore.Qt.LowEventPriority + 1) return # no PUID next(result=None) diff --git a/picard/tagger.py b/picard/tagger.py index f2ffc927a..8c6ff06a1 100644 --- a/picard/tagger.py +++ b/picard/tagger.py @@ -79,7 +79,7 @@ from picard.util import ( pathcmp, partial, ) -from picard.util.thread import ThreadAssist, ThreadPool +from picard.util.thread import ThreadPool from picard.webservice import XmlWebService diff --git a/picard/util/thread.py b/picard/util/thread.py index fd8a256e4..0a8475d57 100644 --- a/picard/util/thread.py +++ b/picard/util/thread.py @@ -36,19 +36,18 @@ class ProxyToMainEvent(QtCore.QEvent): class Thread(QtCore.QThread): - queue = Queue() - - def __init__(self, parent=None): + def __init__(self, parent, queue): QtCore.QThread.__init__(self, parent) + self.queue = queue self.stopping = False def stop(self): self.stopping = True - Thread.queue.put(None) + self.queue.put(None) def run(self): while not self.stopping: - item = Thread.queue.get() + item = self.queue.get() if item is None: continue func, next, priority = item @@ -73,7 +72,10 @@ class ThreadPool(QtCore.QObject): def __init__(self, parent=None): QtCore.QObject.__init__(self, parent) - self.threads = [Thread(self) for i in xrange(3)] + self.queue = Queue() + self.threads = [Thread(self, self.queue) for i in xrange(3)] + self.ofa_queue = Queue() + self.threads.append(Thread(self, self.ofa_queue)) ThreadPool.instance = self def start(self): @@ -87,7 +89,10 @@ class ThreadPool(QtCore.QObject): thread.wait() def call(self, func, next, priority=QtCore.Qt.LowEventPriority): - Thread.queue.put((func, next, priority)) + self.queue.put((func, next, priority)) + + def ofa_call(self, func, next, priority=QtCore.Qt.LowEventPriority): + self.ofa_queue.put((func, next, priority)) def event(self, event): if isinstance(event, ProxyToMainEvent):