code: def _thread_loop(self):
          
          last_check_time = time.time()
          messages = []
          while True:
              # Get first message from queue, blocking until the next time we
              # should be sending
              time_since_last_check = time.time() - last_check_time
              time_till_next_check = max(0, self.interval - time_since_last_check)
              try:
                  message = self._queue.get(timeout=time_till_next_check)
              except queue.Empty:
                  pass
              else:
                  if message is None:
                      # None is the signal to stop this background thread
                      break
                  messages.append(message)
  
                  # Get any other messages currently on queue without blocking,
                  # paying attention to None ("stop thread" signal)
                  should_stop = False
                  while True:
                      try:
                          message = self._queue.get_nowait()
                      except queue.Empty:
                          break
                      if message is None:
                          should_stop = True
                          break
                      messages.append(message)
                  if should_stop:
                      break
  
              # If it's time to send, send what we've collected
              current_time = time.time()
              if current_time - last_check_time >= self.interval:
                  last_check_time = current_time
                  for i in range(0, len(messages), self.batch_size):
                     batch = messages[i:i + self.batch_size]
                     self.send_socket(b''.join(batch))
                  messages = []
  
          # Send any final messages before exiting thread
          for i in range(0, len(messages), self.batch_size):
              batch = messages[i:i + self.batch_size]
              self.send_socket(b''.join(batch))
docs: Background thread used when Sender is in asynchronous/interval mode.