Special thread queue for decoding and fingerpringint, neither FFmeg nor libofa like beeing called from multiple threads.

This commit is contained in:
Lukáš Lalinský
2007-09-09 19:12:58 +02:00
parent f41eae279d
commit df08dd4f53
3 changed files with 16 additions and 11 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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):