title: Troubleshooting PyQt4 Matplotlib
body: <p>So I managed to write a PyQt4 Widget, which can run a loop in a thread. 2 Things are done in the thread. </p>
  
  <ol>
  <li><p>A loop is started and a signal is emitted to a progress bar to give info about progress. (I know this could be done better but for my task is sufficient)</p></li>
  <li><p>After the loop is done running, a pandas.DataFrame is emitted from inside the thread to matplotlib, which is outside the thread and in the main Widget class.</p></li>
  </ol>
  
  <p>Everything works fine, you can move the Widget while the loop is processed. The only Problem is that when the Widget is moved at the same time as the plot is popped up (or the processing is done), everything freezes. Not only the Widget and the plot but also my windows desktop. I can get out of it with task manager. Any Advice how to circumvent this?</p>
  
  <p>I am using Python 3.6 (32 bit)</p>
  
  <p>code:</p>
  
  <pre><code>import sys
  from PyQt4.QtGui import *
  from PyQt4.QtCore import *
  import matplotlib.pyplot as plt
  import pandas as pd
  
  class App(QMainWindow):
  
      def __init__(self):
          super(App, self).__init__()
          self.setGeometry(500, 300, 820, 350)
          self.setWindowTitle("Program")
          self.initUI()
  
      def initUI(self):
  
          #Buttons
          btnposx = 30
          btnposy = 50
  
          self.btn4 = QPushButton('Load', self)
          self.btn4.move(btnposx,btnposy+220)       
          self.btn4.released.connect(self.thread)
  
          #ProgressBar
          self.pb = QProgressBar(self)
          self.pb.move(btnposx+150,btnposy+220)
          self.pb.resize(470,27)        
  
          self.show()
  
      @pyqtSlot(float)
      def load(self, val):
          self.pb.setValue(val)
  
      @pyqtSlot(object)
      def plot(self, pq):
          pq.plot(grid = 1)
          plt.show()
  
      def thread(self):
          self.thread_ = Thread()
          self.thread_.pb_signal.connect(self.load, Qt.QueuedConnection)
          self.thread_.plot_signal.connect(self.plot, Qt.QueuedConnection)
          self.thread_.start()
  
  class Thread(QThread):
      pb_signal = pyqtSignal(float)
      plot_signal = pyqtSignal(object)
  
      def __init__(self, *args, **kwargs):
          QThread.__init__(self, *args, **kwargs)
  
      def __del__(self):
          self.wait()
  
      @pyqtSlot()    
      def run(self):       
          val = 0
          self.pb_signal.emit(20)
          l = range(50000000)
          for i in l:
              val += 1
          self.pb_signal.emit(60)
          self.pb_signal.emit(100)
          pq = pd.DataFrame(data = {'col1':[1,2,3,4,5,6], 'col2':[6,5,4,3,2,1]})
          self.plot_signal.emit(pq)        
          return
  
  if __name__ == '__main__':
      app = QApplication(sys.argv)
      ex = App()
      ex.show()
      sys.exit(app.exec_())
  </code></pre>