code: def run(self):
          
  
          try:
              self._connect()
              self._register()
              while True:
                  try:
                      body = self.command_queue.get(block=True, timeout=1 * SECOND)
                  except queue.Empty:
                      body = None
  
                  if body is not None:
                      result = self._send(body)
                      if result:
                          self.command_queue.task_done()
                      else:
                          # Something was wrong with the socket.
                          self._disconnect()
                          self._connect()
                          self._register()
  
                  # Check for stop event after a read from the queue. This is to
                  # allow you to open a socket, immediately send to it, and then
                  # stop it. We do this in the Metadata send at application start
                  # time
                  if self._stop_event.is_set():
                      logger.debug("CoreAgentSocket thread stopping.")
                      break
          except Exception:
              logger.debug("CoreAgentSocket thread exception.")
          finally:
              self._started_event.clear()
              self._stop_event.clear()
              self._stopped_event.set()
              logger.debug("CoreAgentSocket thread stopped.")
docs: Called by the threading system