title: How to kill a running thread
body: <p>I have a dialog that show the progress of a running thread:</p>
  
  <pre><code>from PyQt5.QtWidgets import *
  from PyQt5.uic import loadUi
  from PyQt5.QtCore import *
  
  class LoaderProgress(QDialog):
      def __init__(self, parent=None):
          super(LoaderProgress, self).__init__(parent)
          loadUi("CliReportsUI/loaderprogress.ui", self)
          self.pbLoader.setValue(0)
          self.btn_cancel.clicked.connect(self.killthread)
  
      def watchthread(self,worker):
          self.thread = worker(self)
          self.thread.totsignal.connect(self.pbLoader.setMaximum)
          self.thread.cntsignal.connect(self.updateprogress)
          self.thread.finished.connect(self.close)
  
      def settitle(self,title):
          self.setWindowTitle(title)
  
      def startthread(self):
          self.thread.start()
  
      def updateprogress(self,n):
          self.pbLoader.setValue(n)
  
      def killthread(self):
          print('How do I do this')
  </code></pre>
  
  <p>Method in another class runs the thread in the following manner:</p>
  
  <pre><code>    dlg = LoaderProgress(self)
      dlg.watchthread(FileLoader)
      dlg.settitle("Loading The Master File...")
      dlg.show()
      dlg.startthread()
  </code></pre>
  
  <p>Then there is the worker class:</p>
  
  <pre><code>class FileLoader(QThread):
      totsignal = pyqtSignal(int)
      cntsignal = pyqtSignal(int)
  
      def __init__(self,parent=None):
          super(FileLoader, self).__init__(parent)
          self.threadactive = True
          self.total = 100
  
      def run(self):
          self.totsignal.emit(self.total)
          i = 1
          while(i &lt; self.total and self.threadactive):
              print(time.time)
              if(time.time() % 1==0):
                  i+=1
                  self.cntsignal.emit(i)
  </code></pre>
  
  <p>On the loader dialog I have a button that will cancel the process (btn_cancel) but I do not know how to kill the running thread if the cancel button is clicked.  Thanks for any assistance.</p>