Dear developers,
I am the maintainer of the plugin ClusterPoint [2018].
I made an effort to put all the heavy computations into tasks of type QgsTask and let the user cancel, if execution takes too long.
This worked perfectly fine in QGIS 3.10, but stopped working in QGIS 3.16.
Firstly, the tasks do not finish any more. The status of the task remains at 2, so it does not change to finished any more.
Secondly, QGIS crashes when the task is canceled by the user.
At the bottom of this email, there are some python code snippets of my plugin.
Otherwise, the main code is available at https://github.com/jjenkner/ClusterPoints/blob/version_4.11/ClusterPoints_algorithm.py
Please help. I have no idea how to fix this in QGIS 3.16.
Cheers,
Johannes
----------------------
task = ClusterTask("K-Means clustering", \
None,points,PercentAttrib, \
NumberOfClusters,d,Distance_Type==1)
None,points,PercentAttrib, \
NumberOfClusters,d,Distance_Type==1)
...
# run potentially expensive clustering in extra task
QgsApplication.taskManager().addTask(task)
while task.status()<3:
sleep(1)
if progress.isCanceled():
progress.pushInfo(self.tr("Execution canceled by user"))
task.cancel()
QgsApplication.taskManager().addTask(task)
while task.status()<3:
sleep(1)
if progress.isCanceled():
progress.pushInfo(self.tr("Execution canceled by user"))
task.cancel()
break
...
class ClusterTask(QgsTask):
def __init__(self, description, link, points, pa, k, d, manhattan=False):
super().__init__(description, QgsTask.CanCancel)
self.link = link
self.points = points
self.pa = pa
self.k = k
self.d = d
self.manhattan = manhattan
self.clusters = []
self.tree_progress = 0
super().__init__(description, QgsTask.CanCancel)
self.link = link
self.points = points
self.pa = pa
self.k = k
self.d = d
self.manhattan = manhattan
self.clusters = []
self.tree_progress = 0
def cancel(self):
QgsMessageLog.logMessage("Cluster task canceled",
MESSAGE_CATEGORY, Qgis.Critical)
super().cancel()
QgsMessageLog.logMessage("Cluster task canceled",
MESSAGE_CATEGORY, Qgis.Critical)
super().cancel()
def run(self):
"""
Execution of task
"""
QgsMessageLog.logMessage(self.description(),MESSAGE_CATEGORY, Qgis.Info)
if self.description().startswith("K-Means"):
return self.kmeans()
elif self.description().startswith("Hierarchical"):
if "SLINK" in self.description():
return self.hcluster_slink()
else:
return self.hcluster()
"""
Execution of task
"""
QgsMessageLog.logMessage(self.description(),MESSAGE_CATEGORY, Qgis.Info)
if self.description().startswith("K-Means"):
return self.kmeans()
elif self.description().startswith("Hierarchical"):
if "SLINK" in self.description():
return self.hcluster_slink()
else:
return self.hcluster()
def finished(self,result):
"""
Called upon finish of execution
"""
if result:
QgsMessageLog.logMessage(self.tr("Successful execution of clustering task"),
MESSAGE_CATEGORY, Qgis.Success)
else:
QgsMessageLog.logMessage(self.tr("Execution of clustering task failed"),
MESSAGE_CATEGORY, Qgis.Critical)
"""
Called upon finish of execution
"""
if result:
QgsMessageLog.logMessage(self.tr("Successful execution of clustering task"),
MESSAGE_CATEGORY, Qgis.Success)
else:
QgsMessageLog.logMessage(self.tr("Execution of clustering task failed"),
MESSAGE_CATEGORY, Qgis.Critical)
...
_______________________________________________ QGIS-Developer mailing list [email protected] List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer
