1

I would like to run a QgsTask when I push a button in a Qgis plugin (3.10). My task is a subclass similar to this example

In the main class of my plugin, I have added this (connected to the button that works) :

def myBtnAction(self) :
    from .my_task import MyTask
    task = MyTask('run my task', 20)
    QgsApplication.taskManager().addTask(task)

The task is never executed.

3
  • Which qgis 3.10 version are you running? Is it up to date?
    – ndawson
    Commented Jun 26, 2020 at 21:05
  • I use the last version of QGIS LTR, up to date.
    – TrsBar
    Commented Jul 2, 2020 at 7:12
  • Are you sure that it is not executed? Or is its finished method never called maybe? Commented Sep 7, 2022 at 13:01

1 Answer 1

2

Did you try the standalone version running in PyQGIS Python console like below (clearly borrowed from your link and reindented)?

class MyTask(QgsTask):
    def __init__(self, description, flags):
        super().__init__(description, flags)
    def run(self):
        QgsMessageLog.logMessage('Started task {}'.format(self.description()))
        #print('crashandburn')
        return True

t1 = MyTask('waste cpu', QgsTask.CanCancel)
QgsApplication.taskManager().addTask(t1)

In my case, it "works". So what does MyTask from your from .my_task import MyTask looks like? Did you try to use your task code outside the plugin to find where the issue could be?

1
  • Yes, the code works well in the python console, no problem. Nothing blocking i've tested on a new plugin from scratch to be sure that the problem doesn't come from my code.
    – TrsBar
    Commented Jun 18, 2020 at 10:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.