[QGIS-Developer] (Multi)Threads in QGIS plugins

Matthijs Bon thijssie2008 at gmail.com
Mon Jul 31 23:34:03 PDT 2017


Hi,

I was working on a plugin, but I wanted to increase performance by using
multiple threads for my plugin. I was doing this either by creating a
QObject and moving it to a new QThread, but I also tried inheriting from a
QThread class, but both options didn't have any performance increase.

In general my code workflow is as follows (I tried both 1a and 1b):
1a. plugin_dialog.accept() starts two workers (class
FeatureSelector(QThread))
1b. plugin_dialog.accept() starts two workers (class Worker(QObject)) and
moves each instance to a seperate QThread
2. Each worker iterates over half of the total features and select features
based on a expression (QgsFeatureRequest().setFilterExpression(expression)).
3. On signal finished of each FeatureSelector instance, the return values
are put back together again and used to create a new memory layer)

I thought, maybe QGIS already optimized threads and therefore, this is the
fastest my plugin is going to be, no matter how many threads I use? Or
maybe there is a better way of running multiple threads in QGIS?

Best,
Matthijs
-- 
*Matthijs Bon*
*Student Geomatics*
*Delft University of Technology*
*4133390*

*T:* +31 (0)6 816 766 79
*E: *thijssie2008 at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/qgis-developer/attachments/20170801/5471e82e/attachment.html>


More information about the QGIS-Developer mailing list