title: Overwriting close function of pyqtgraph application
body: <p>Wanting to visualize realtime data I wanted to use pyqtgraph since it can handle faster streams than matplotlib with less effort.
  I started with following one of its basic examples and added a Thread that reads from a UDP signal to update the data that is plotted every 50ms. The code should work (provided another process is sending data to this UDP port) but the problem starts when the plotting application is closed.</p>
  <p>I searched for the problem, and my guess is that when the application is closed, it first waits on all its processes to finish (so also for the thread to finish). But since the deamon thread only closes when the parent program closes, they both wait on each other.
  I wanted to overwrite the close function of the plotting app to first close the thread before waiting on the rest to exit, but I could not find how to do that.</p>
  <p>help would be very welcome.</p>
  <pre><code>from pyqtgraph.Qt import QtGui, QtCore
  
  import queue
  import numpy as np
  import pyqtgraph as pg
  
  import socket
  from threading import Thread
  import struct
  
  class StreamReader(Thread):
      def __init__(self, queue):
          super().__init__()
          self.queue = queue
          self.insocket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
          self.insocket.bind(('localhost', 54654))
  
      def run(self):
          while True:
              dat, _ = self.insocket.recvfrom(1000)
              val = struct.unpack('!f', dat)
              self.queue.put(val)
  
  app = pg.mkQApp(&quot;plot datastream&quot;)
  win = pg.GraphicsLayoutWidget(show=True, title=&quot;UDP datastream&quot;)
  win.resize(1000,600)
  win.setWindowTitle(&quot;PoC real-time graph&quot;)
  
  pg.setConfigOptions(antialias=True)
  
  p1 = win.addPlot(title=&quot;real-time plot&quot;)
  curve = p1.plot(pen=&quot;y&quot;)
  
  q = queue.Queue()
  sr = StreamReader(q)
  sr.deamon=True
  sr.start()
  data = np.zeros(1000)
  ptr=0
  def update():
      global curve, data, ptr, p1
      while not q.empty():
          newval = q.get()
          data = np.append(data, newval)
      if data.size &gt; 1000:
          data = data[-1000:]
      curve.setData(data)
      ptr += 1
  
  timer = QtCore.QTimer()
  timer.timeout.connect(update)
  timer.start(50)
  
  if __name__ == &quot;__main__&quot;:
      pg.mkQApp().exec_()
  </code></pre>