<html><head></head><body><div style="font-family: Verdana;font-size: 12.0px;"><div>Dear developers,</div>

<div> </div>

<div>I am the maintainer of the plugin ClusterPoint [2018].</div>

<div> </div>

<div>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.</div>

<div> </div>

<div>This worked perfectly fine in QGIS 3.10, but stopped working in QGIS 3.16.</div>

<div> </div>

<div>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.</div>

<div>Secondly, QGIS crashes when the task is canceled by the user.</div>

<div> </div>

<div>At the bottom of this email, there are some python code snippets of my plugin.</div>

<div>Otherwise, the main code is available at https://github.com/jjenkner/ClusterPoints/blob/version_4.11/ClusterPoints_algorithm.py</div>

<div> </div>

<div>Please help. I have no idea how to fix this in QGIS 3.16.</div>

<div> </div>

<div>Cheers,</div>

<div> </div>

<div>Johannes</div>

<div> </div>

<div> </div>

<div>----------------------</div>

<div> </div>

<div>            task = ClusterTask("K-Means clustering", \<br/>
                               None,points,PercentAttrib, \<br/>
                               NumberOfClusters,d,Distance_Type==1)</div>

<div> </div>

<div>...</div>

<div> </div>

<div>
<div>        # run potentially expensive clustering in extra task<br/>
        QgsApplication.taskManager().addTask(task)<br/>
        <br/>
        while task.status()<3:<br/>
            sleep(1)<br/>
            if progress.isCanceled():<br/>
                progress.pushInfo(self.tr("Execution canceled by user"))<br/>
                task.cancel()</div>

<div>                break</div>

<div> </div>

<div>...</div>

<div> </div>
</div>

<div>
<div>class ClusterTask(QgsTask):</div>

<div>    def __init__(self, description, link, points, pa, k, d, manhattan=False):<br/>
        super().__init__(description, QgsTask.CanCancel)<br/>
        self.link = link<br/>
        self.points = points<br/>
        self.pa = pa<br/>
        self.k = k<br/>
        self.d = d<br/>
        self.manhattan = manhattan<br/>
        self.clusters = []<br/>
        self.tree_progress = 0</div>

<div>    def cancel(self):<br/>
        QgsMessageLog.logMessage("Cluster task canceled",<br/>
            MESSAGE_CATEGORY, Qgis.Critical)<br/>
        super().cancel()</div>

<div>    def run(self):<br/>
        """<br/>
        Execution of task<br/>
        """<br/>
    <br/>
        QgsMessageLog.logMessage(self.description(),MESSAGE_CATEGORY, Qgis.Info)<br/>
        if self.description().startswith("K-Means"):<br/>
            return self.kmeans()<br/>
        elif self.description().startswith("Hierarchical"):<br/>
            if "SLINK" in self.description():<br/>
                return self.hcluster_slink()<br/>
            else:<br/>
                return self.hcluster()</div>

<div>    def finished(self,result):<br/>
        """<br/>
        Called upon finish of execution<br/>
        """<br/>
        <br/>
        if result:<br/>
             QgsMessageLog.logMessage(self.tr("Successful execution of clustering task"),<br/>
                       MESSAGE_CATEGORY, Qgis.Success)<br/>
        else:<br/>
             QgsMessageLog.logMessage(self.tr("Execution of clustering task failed"),<br/>
                       MESSAGE_CATEGORY, Qgis.Critical)</div>

<div> </div>

<div>...</div>
        </div>

<div> </div>

<div> </div></div></body></html>