Use the global thread pool, like the docs suggest
This commit is contained in:
@@ -73,7 +73,7 @@ logger = logging.getLogger(__name__)
|
||||
# Main Program
|
||||
##
|
||||
|
||||
# Global config singleton
|
||||
# Global config and data singletons
|
||||
CONFIG = Config()
|
||||
SHARED = SharedData()
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
##
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user