code: def _write_loop(self):
          
          while self.state == 'connected':
              # to simplify the timeout handling, use the maximum of the
              # ping interval and ping timeout as timeout, with an extra 5
              # seconds grace period
              timeout = max(self.ping_interval, self.ping_timeout) + 5
              packets = None
              try:
                  packets = [self.queue.get(timeout=timeout)]
              except self.queue.Empty:
                  self.logger.error('packet queue is empty, aborting')
                  self._reset()
                  break
              if packets == [None]:
                  self.queue.task_done()
                  packets = []
              else:
                  while True:
                      try:
                          packets.append(self.queue.get(block=False))
                      except self.queue.Empty:
                          break
                      if packets[-1] is None:
                          packets = packets[:-1]
                          self.queue.task_done()
                          break
              if not packets:
                  # empty packet list returned -> connection closed
                  break
              if self.current_transport == 'polling':
                  p = payload.Payload(packets=packets)
                  r = self._send_request(
                      'POST', self.base_url, body=p.encode(),
                      headers={'Content-Type': 'application/octet-stream'})
                  for pkt in packets:
                      self.queue.task_done()
                  if r is None:
                      self.logger.warning(
                          'Connection refused by the server, aborting')
                      break
                  if r.status_code != 200:
                      self.logger.warning('Unexpected status code %s in server '
                                          'response, aborting', r.status_code)
                      self._reset()
                      break
              else:
                  # websocket
                  try:
                      for pkt in packets:
                          self.ws.send(pkt.encode())
                          self.queue.task_done()
                  except websocket.WebSocketConnectionClosedException:
                      self.logger.warning(
                          'WebSocket connection was closed, aborting')
                      break
          self.logger.info('Exiting write loop task')
docs: This background task sends packages to the server as they are
          pushed to the send queue.