Using threads in QGIS python plugins

I really wanted to write this post since a long time but things got in the way, and now an email finally triggered me.

As part of a consultancy I got to work with threads in a python plugin for QGIS. Since it was a pretty tedious process, I decided to write  the whole thing fairly generic so that it could be used easily by others.

Before using this, please note that there are ongoing efforts to get something like this directly in QGIS 3.

The code below (or maybe a more recent version – the one posted here is 1da300f from May 6, 2015) can be found on github

The usage is pretty self explanatory but it goes like this. You create your worker class that inherits from AbstractWorker and implement the work method:

in your code you import all the needed modules and functions and call your ExampleWorker like this:

here, for reference, the whole code

Hope this could help you, if you need professional help don’t hesitate contacting us

Posted in Python, QGIS, QGIS Plugins
4 Comments » for Using threads in QGIS python plugins
  1. Can you debbug this thread in pydev?
    I can’t debugg it yet

    salut!

  2. I got a question about this piece of code

    worker.set_message.connect(lambda message: set_worker_message(
    message, message_bar_item))

    ¿Where you defined the variable message_bar_item on the function start_worker?

    thanks a lot!!

  3. marco says:

    I updated the code, it was a typo

Leave a Reply

%d bloggers like this: