Use the global thread pool, like the docs suggest

This commit is contained in:
Veronica Berglyd Olsen
2023-09-10 18:15:16 +02:00
parent e210bca319
commit 3f91f5c506
3 changed files with 8 additions and 11 deletions
+1 -1
View File
@@ -73,7 +73,7 @@ logger = logging.getLogger(__name__)
# Main Program
##
# Global config singleton
# Global config and data singletons
CONFIG = Config()
SHARED = SharedData()
+3 -6
View File
@@ -68,10 +68,6 @@ class SharedData(QObject):
self._idleTime = 0.0
self._idleRefTime = time()
# Threading
self._threadPool = QThreadPool(self)
self._threadPool.setMaxThreadCount(5)
return
##
@@ -138,7 +134,8 @@ class SharedData(QObject):
self._gui = gui
self._theme = theme
self._resetProject()
logger.debug("SharedData instance initialised")
logger.debug("Ready: SharedData")
logger.debug("Thread Pool Max Count: %d", QThreadPool.globalInstance().maxThreadCount())
return
def openProject(self, path: str | Path, clearLock: bool = False) -> bool:
@@ -210,7 +207,7 @@ class SharedData(QObject):
def runInThreadPool(self, runnable: QRunnable, priority: int = 0) -> None:
"""Queue a runnable in the application thread pool."""
self._threadPool.start(runnable, priority=priority)
QThreadPool.globalInstance().start(runnable, priority=priority)
return
##
+4 -4
View File
@@ -24,7 +24,7 @@ import pytest
from mocked import causeOSError
from tools import C, buildTestProject
from PyQt5.QtCore import Qt
from PyQt5.QtCore import QThreadPool, Qt
from PyQt5.QtGui import QTextBlock, QTextCursor, QTextOption
from PyQt5.QtWidgets import QAction, qApp
@@ -1107,7 +1107,7 @@ def testGuiEditor_WordCounters(qtbot, monkeypatch, nwGUI, projPath, ipsumText, m
return self._objID
threadPool = MockThreadPool()
monkeypatch.setattr(SHARED, "_threadPool", threadPool)
monkeypatch.setattr(QThreadPool, "globalInstance", lambda *a: threadPool)
nwGUI.docEditor.wcTimerDoc.blockSignals(True)
nwGUI.docEditor.wcTimerSel.blockSignals(True)
@@ -1146,7 +1146,7 @@ def testGuiEditor_WordCounters(qtbot, monkeypatch, nwGUI, projPath, ipsumText, m
# Run the full word counter
nwGUI.docEditor._runDocCounter()
assert SHARED._threadPool.objectID() == id(nwGUI.docEditor.wCounterDoc)
assert threadPool.objectID() == id(nwGUI.docEditor.wCounterDoc)
nwGUI.docEditor.wCounterDoc.run()
# nwGUI.docEditor._updateDocCounts(cC, wC, pC)
@@ -1162,7 +1162,7 @@ def testGuiEditor_WordCounters(qtbot, monkeypatch, nwGUI, projPath, ipsumText, m
# Run the selection word counter
nwGUI.docEditor._runSelCounter()
assert SHARED._threadPool.objectID() == id(nwGUI.docEditor.wCounterSel)
assert threadPool.objectID() == id(nwGUI.docEditor.wCounterSel)
nwGUI.docEditor.wCounterSel.run()
# nwGUI.docEditor._updateSelCounts(cC, wC, pC)