title: How to optimize my code for better performance and no lag in realtime
body: <p>I have a app with pyqt5 and receive data from <code>udp</code>, pack them and show.</p>
  <p>I use threading(python built-in thread) for my app(one thread for <code>dl_data</code>, one thread for <code>save_log</code> and one thread for <code>ui</code>) but in real time I have a lots of lag in showing final image.</p>
  <p>Part of my code for pack data is:</p>
  <pre><code>self.data_log =  [[0 for i in range(1000)] for j in range(1600)]
  def unpack(self,pack):
          tmp = bytearray()
          for i in range(3):
              tmp.extend(pack[i])
          
          return np.asarray([newdiv(struct.unpack('&lt;H',tmp[x+1:x+3])[0],256) for x in range(0,(self.NP) * 4,4)])
  
  def merge(self,data):
          data = self.unpack(data)
          data = np.roll(data,200,0)
          self.data_log.extend([data])
  
  def dl_data(self):
      while 1:
          for i in range(self.NPBN * 3):
              tmp = self.recv(self.bytes)
              self.merge(tmp)
  def process_feed(self):
      while True:
          data = self.tcpsocket.recv(1024)
          if b'pressed' in data :
              if not self.get_data.is_alive():
                  self.get_data.start()
  def show(self):
     .....
  if self.Mode == 'run':
      pressed= threading.Thread(target=self.process_feed)
      pressed.start()
      get_data = threading.Thread(target=self.dl_data)
  </code></pre>
  <p>newdiv function is &quot;Making division in Python faster&quot; <a href="https://fredrikj.net/blog/2008/07/making-division-in-python-faster/" rel="nofollow noreferrer">link</a></p>