ProcessingConfig: added multithread max thread setting, TilesXYZ: max thread now inherrrits from ProcessingConfig

This commit is contained in:
Isghj5 2019-08-04 18:21:49 -07:00 committed by Nyall Dawson
parent ba17f3b81e
commit 9fd93a1013
2 changed files with 12 additions and 3 deletions

View File

@ -50,7 +50,7 @@ from qgis.core import (QgsProcessingException,
from processing.algs.qgis.QgisAlgorithm import QgisAlgorithm
import threading
from concurrent.futures import ThreadPoolExecutor
from multiprocessing import cpu_count
from processing.core.ProcessingConfig import ProcessingConfig
# TMS functions taken from https://alastaira.wordpress.com/2011/07/06/converting-tms-tile-coordinates-to-googlebingosm-tile-coordinates/ #spellok
@ -235,8 +235,7 @@ class TilesXYZAlgorithmBase(QgisAlgorithm):
self.tile_format = self.formats[self.parameterAsEnum(parameters, self.TILE_FORMAT, context)]
self.quality = self.parameterAsInt(parameters, self.QUALITY, context)
self.metatilesize = self.parameterAsInt(parameters, self.METATILESIZE, context)
self.maxThreads = QgsApplication.maxThreads()
self.maxThreads = cpu_count() if self.maxThreads == -1 else self.maxThreads # if unbound, maxThreads() returns -1
self.maxThreads = int(ProcessingConfig.getSetting(ProcessingConfig.MAX_THREADS))
try:
self.tile_width = self.parameterAsInt(parameters, self.TILE_WIDTH, context)
self.tile_height = self.parameterAsInt(parameters, self.TILE_HEIGHT, context)

View File

@ -31,6 +31,7 @@ from qgis.core import (NULL,
QgsRasterFileWriter)
from processing.tools.system import defaultOutputFolder
import processing.tools.dataobjects
from multiprocessing import cpu_count
class SettingsWatcher(QObject):
@ -56,6 +57,7 @@ class ProcessingConfig:
WARN_UNMATCHING_CRS = 'WARN_UNMATCHING_CRS'
SHOW_PROVIDERS_TOOLTIP = 'SHOW_PROVIDERS_TOOLTIP'
SHOW_ALGORITHMS_KNOWN_ISSUES = 'SHOW_ALGORITHMS_KNOWN_ISSUES'
MAX_THREADS = 'MAX_THREADS'
settings = {}
settingIcons = {}
@ -135,6 +137,14 @@ class ProcessingConfig:
valuetype=Setting.SELECTION,
options=invalidFeaturesOptions))
threads = QgsApplication.maxThreads() # if user specified limit for rendering, lets keep that as default here, otherwise max
threads = cpu_count() if threads == -1 else threads # if unset, maxThreads() returns -1
ProcessingConfig.addSetting(Setting(
ProcessingConfig.tr('General'),
ProcessingConfig.MAX_THREADS,
ProcessingConfig.tr('Max Threads'), threads,
valuetype=Setting.INT))
@staticmethod
def setGroupIcon(group, icon):
ProcessingConfig.settingIcons[group] = icon