def cancel(self): self.con.cancel( ) #psycopg2 conection can be cancelled from any thread. QgsTask.cancel(self)