parameters: (self)
docstring: Run in a loop to recv/send message to the ModelServer manager
          :return:
docstring_summary: Run in a loop to recv/send message to the ModelServer manager
          :return:
docstring_tokens: Run in a loop to recv / send message to the ModelServer manager : return :
function: def run_loop(self):
          """
          Run in a loop to recv/send message to the ModelServer manager
          :return:
          """
  
          while (1):
              try:
                  data_available = False
                  while not data_available:
                      now = datetime.datetime.now()
                      # Try sending any pending messages that haven't been acknowledged yet.
                      for msg_id in self.pending_msgs:
                          (send_id, recv_id, data), last_sent = self.pending_msgs[msg_id]
                          if (last_sent - now).seconds > ModelServer.RETRY_TIMEOUT:
                              self._send_msg(msg_id, send_id, recv_id, data)
                      # Poll for up to 250 milliseconds to see if there are any incoming events.
                      data_available = 0 != self.socket.poll(ModelServer.POLL_TIMEOUT)
                  payload = self._recv()
              except UnicodeError as e:
                  logging.warning(f"Failed to decode : {e.reason}")
                  continue
              except KeyboardInterrupt:
                  if self._closing:
                      logging.warning("Forced shutting down now.")
                      os._exit(-1)
                  else:
                      logging.info("Received KeyboardInterrupt. Ctrl+C again to force shutting down.")
                      self._closing = True
                      continue
  
              msg_id, send_id, recv_id, msg = self._parse_msg(payload)
  
              # If this is an acknowledgment, clear the corresponding pending message.
              if recv_id == MessengerCallback.ACK:
                  self.pending_msgs.pop(msg_id, None)
                  continue
              if msg is None:
                  continue
              else:
                  result, cont = self._execute_cmd(msg.cmd, msg.data)
                  if not cont:
                      logging.info("Shutting down.")
                      break
  
                  # Currently not expecting to invoke any callback on ModelServer
                  # side, so second parameter 0
                  self._send_msg(self._next_msg_id(), 0, send_id, result)
function_tokens: def run_loop ( self ) : while ( 1 ) : try : data_available = False while not data_available : now = datetime . datetime . now ( ) # Try sending any pending messages that haven't been acknowledged yet. for msg_id in self . pending_msgs : ( send_id , recv_id , data ) , last_sent = self . pending_msgs [ msg_id ] if ( last_sent - now ) . seconds > ModelServer . RETRY_TIMEOUT : self . _send_msg ( msg_id , send_id , recv_id , data ) # Poll for up to 250 milliseconds to see if there are any incoming events. data_available = 0 != self . socket . poll ( ModelServer . POLL_TIMEOUT ) payload = self . _recv ( ) except UnicodeError as e : logging . warning ( f"Failed to decode : {e.reason}" ) continue except KeyboardInterrupt : if self . _closing : logging . warning ( "Forced shutting down now." ) os . _exit ( - 1 ) else : logging . info ( "Received KeyboardInterrupt. Ctrl+C again to force shutting down." ) self . _closing = True continue msg_id , send_id , recv_id , msg = self . _parse_msg ( payload ) # If this is an acknowledgment, clear the corresponding pending message. if recv_id == MessengerCallback . ACK : self . pending_msgs . pop ( msg_id , None ) continue if msg is None : continue else : result , cont = self . _execute_cmd ( msg . cmd , msg . data ) if not cont : logging . info ( "Shutting down." ) break # Currently not expecting to invoke any callback on ModelServer # side, so second parameter 0 self . _send_msg ( self . _next_msg_id ( ) , 0 , send_id , result )