Bug report #19762

QgsApplication.setMaxThreads not work appropriately

Added by Francisco Raga almost 2 years ago. Updated almost 2 years ago.

Status:Closed
Priority:Normal
Assignee:-
Category:Unknown
Affected QGIS version:3.3(master) Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:No Copied to github as #:27587

Description

qgis documentation say that if maxthreads is -1 means use all available cores.but no set any value if put -1

sample code :

from qgis.core import QgsApplication
from qgis.core import QgsApplication
QgsApplication.setMaxThreads(-1)

for solved this issue now:

from PyQt5.QtCore import QThread
from qgis.core import QgsApplication
threadcount = QThread.idealThreadCount()
QgsApplication.setMaxThreads(threadcount)

c++ code: https://qgis.org/api/qgsapplication_8cpp_source.html#l01645

3cores.png (153 KB) Francisco Raga, 2018-09-29 12:08 PM

8cores.png (155 KB) Francisco Raga, 2018-09-29 12:08 PM

minus1.png (138 KB) Francisco Raga, 2018-09-29 12:08 PM

History

#1 Updated by Jürgen Fischer almost 2 years ago

  • Status changed from Open to Feedback

How is that different from the quoted code?

#2 Updated by Francisco Raga almost 2 years ago

Jürgen Fischer wrote:

How is that different from the quoted code?

then -1 set max thread if we see the API and it just does not do anything

#3 Updated by Jürgen Fischer almost 2 years ago

Francisco Raga wrote:

Jürgen Fischer wrote:

How is that different from the quoted code?

then -1 set max thread if we see the API and it just does not do anything

What do you mean? If maxThreads is -1 it fetches QThread::idealThreadCount() and set that - like your code.

void QgsApplication::setMaxThreads( int maxThreads )
 {
   QgsDebugMsg( QString( "maxThreads: %1" ).arg( maxThreads ) );

   // make sure value is between 1 and #cores, if not set to -1 (use #cores)
   // 0 could be used to disable any parallel processing
   if ( maxThreads < 1 || maxThreads > QThread::idealThreadCount() )
     maxThreads = -1;

   // save value
   ABISYM( mMaxThreads ) = maxThreads;

   // if -1 use #cores
   if ( maxThreads == -1 )
     maxThreads = QThread::idealThreadCount();

   // set max thread count in QThreadPool
   QThreadPool::globalInstance()->setMaxThreadCount( maxThreads );
   QgsDebugMsg( QString( "set QThreadPool max thread count to %1" ).arg( QThreadPool::globalInstance()->maxThreadCount() ) );
 }

#4 Updated by Francisco Raga almost 2 years ago

Jürgen Fischer wrote:

Francisco Raga wrote:

Jürgen Fischer wrote:

How is that different from the quoted code?

then -1 set max thread if we see the API and it just does not do anything

What do you mean? If maxThreads is -1 it fetches QThread::idealThreadCount() and set that - like your code.

[...]

Yes ,I know,but it doesn't work , When I put -1 , it doesn't check the QComboBox and doesn't change the spinbox,(attach minus1.png) but my pc have 8 cores,and now I write 3 or 8 , it sets the value well . It's weird,I know

#5 Updated by Jürgen Fischer almost 2 years ago

  • Resolution set to invalid
  • Status changed from Feedback to Closed

Francisco Raga wrote:

Yes ,I know,but it doesn't work , When I put -1 , it doesn't check the QComboBox and doesn't change the spinbox,(attach minus1.png) but my pc have 8 cores,and now I write 3 or 8 , it sets the value well . It's weird,I know

That's the intended behavior. The checkbox expresses a limit and the spinbox shows what the limit is. -1 means unlimited and so the checkbox isn't checked. It just doesn't check whether the upper limit is also the physical limit - but effectively it's the same.

Also available in: Atom PDF