Introduce a priority thread pool

This pool is meant to be used for threads where the user expects a response as fast as possible.
This commit is contained in:
Philipp Wolfer
2019-02-16 21:45:52 +01:00
committed by Philipp Wolfer
parent de4bf2029a
commit f1248b487f
2 changed files with 9 additions and 1 deletions

View File

@@ -160,6 +160,12 @@ class Tagger(QtWidgets.QApplication):
# It's a valid reference, but its start() method doesn't work.
self.thread_pool = QtCore.QThreadPool(self)
# Provide a separate thread pool for operations that should not be
# delayed by longer background processing tasks, e.g. because the user
# expects instant feedback instead of waiting for a long list of
# operations to finish.
self.priority_thread_pool = QtCore.QThreadPool(self)
# Use a separate thread pool for file saving, with a thread count of 1,
# to avoid race conditions in File._save_and_rename.
self.save_thread_pool = QtCore.QThreadPool(self)
@@ -341,6 +347,7 @@ class Tagger(QtWidgets.QApplication):
self._acoustid.done()
self.thread_pool.waitForDone()
self.save_thread_pool.waitForDone()
self.priority_thread_pool.waitForDone()
self.browser_integration.stop()
self.webservice.stop()
self.run_cleanup()

View File

@@ -446,7 +446,8 @@ class MetadataBox(QtWidgets.QTableWidget):
return
if self.selection_dirty:
self._update_selection()
thread.run_task(self._update_tags, self._update_items)
thread.run_task(self._update_tags, self._update_items,
thread_pool=self.tagger.priority_thread_pool)
def _update_tags(self):
self.selection_mutex.lock()