Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QgsTask does not starts after adding to the task manager #27095

Closed
qgib opened this issue Jun 26, 2018 · 3 comments
Closed

QgsTask does not starts after adding to the task manager #27095

qgib opened this issue Jun 26, 2018 · 3 comments
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! PyQGIS Related to the PyQGIS API

Comments

@qgib
Copy link
Contributor

qgib commented Jun 26, 2018

Author Name: Alexander Bruy (@alexbruy)
Original Redmine Issue: 19267
Affected QGIS version: 3.3(master)
Redmine category:python_bindings_/_sipify


Seems adding tasks to the task manager from Python using

task = TestTask('my task', 10)
QgsApplication.taskManager().addTask(task)

works fine from Python console, but does not work from the QAction's slot.

Test plugin attached. Install and activate this plugin, run task from the menu "Plugins → Test → Test". Nothing happens, task does not started. Now open init.py and uncomment line 55 which just adds some dummy debug message to the log. Restart QGIS and run plugin again, task will be added and executed.


@qgib
Copy link
Contributor Author

qgib commented Jun 26, 2018

Author Name: Alexander Bruy (@alexbruy)


There is also another issue — finished() is not executed (probably because Python object is garbage collected when out of scope). To test this uncomment lines 52-53 in the init.py and run plugin. After task completes mo messages will be added to the message log.

@qgib
Copy link
Contributor Author

qgib commented Jul 8, 2018

Author Name: Salvatore Larosa (@slarosa)


Hi Alexander, I don't know if this is or not a bug, but I would have defined the application taskmanager on @init@ method of the testplugin. Code below works as expected.

class TestPlugin:
    def __init__(self, iface):
        self.iface = iface
        self.tm = QgsApplication.taskManager()

    def initGui(self):
        self.action = QAction('Test', self.iface.mainWindow())
        self.iface.addPluginToMenu('Test', self.action)
        self.action.triggered.connect(self.run)

    def unload(self):
        self.iface.removePluginMenu('Test', self.action)

    def run(self):
        task = TestTask('my task', 10)
        self.tm.addTask(task)

    def complete(self):
        QgsMessageLog.logMessage('Task finished')

    def error(self):
        QgsMessageLog.logMessage('Error occurred')
</code>

@qgib
Copy link
Contributor Author

qgib commented Jul 10, 2018

Author Name: Alexander Bruy (@alexbruy)


  • status_id was changed from Open to Closed

@qgib qgib closed this as completed Jul 10, 2018
@qgib qgib added Bug Either a bug report, or a bug fix. Let's hope for the latter! PyQGIS Related to the PyQGIS API labels May 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Either a bug report, or a bug fix. Let's hope for the latter! PyQGIS Related to the PyQGIS API
Projects
None yet
Development

No branches or pull requests

1 participant