Move the thread pool to the shared object instance

This commit is contained in:
Veronica Berglyd Olsen
2023-09-10 17:46:35 +02:00
parent 16e2e0cc83
commit e210bca319
5 changed files with 32 additions and 9 deletions
+15 -1
View File
@@ -29,7 +29,7 @@ from time import time
from typing import TYPE_CHECKING
from pathlib import Path
from PyQt5.QtCore import QObject, pyqtSignal
from PyQt5.QtCore import QObject, QRunnable, QThreadPool, pyqtSignal
from PyQt5.QtWidgets import QMessageBox, QWidget
from novelwriter.core.spellcheck import NWSpellEnchant
@@ -55,14 +55,23 @@ class SharedData(QObject):
def __init__(self) -> None:
super().__init__()
# Objects
self._gui = None
self._theme = None
self._project = None
self._spelling = None
# Settings
self._lockedBy = None
self._alert = None
self._idleTime = 0.0
self._idleRefTime = time()
# Threading
self._threadPool = QThreadPool(self)
self._threadPool.setMaxThreadCount(5)
return
##
@@ -199,6 +208,11 @@ class SharedData(QObject):
self.projectStatusChanged.emit(state)
return
def runInThreadPool(self, runnable: QRunnable, priority: int = 0) -> None:
"""Queue a runnable in the application thread pool."""
self._threadPool.start(runnable, priority=priority)
return
##
# Alert Boxes
##