original_docstring: The main method of this process. It starts the simspark application, connects to it and receives updates of
          the simulation state and also sends scheduled commands to the simulation.
docstring: The main method of this process. It starts the simspark application, connects to it and receives updates of
  the simulation state and also sends scheduled commands to the simulation.
docstring_tokens: The main method of this process . It starts the simspark application connects to it and receives updates of the simulation state and also sends scheduled commands to the simulation .
code: def run(self):
          """The main method of this process. It starts the simspark application, connects to it and receives updates of
          the simulation state and also sends scheduled commands to the simulation."""
          self.__start_application()
  
          while (not self.__start_instance or self.__p.poll() is None) and not self.__cancel.is_set():
              # connect to the simspark instance
              if not self.connected.is_set():
                  self.connect()
              else:
                  length = struct.unpack("!I", self.socket.recv(4))[0]
                  msg = self.socket.recv(length).decode()
                  sexp = sexpr.str2sexpr(msg)
  
                  self.__update_environment(sexp[0])
                  self.__update_scene(sexp[1:])
  
                  # send scheduled (trainer) commands
                  if not self.__cmd_queue.empty():
                      cmd = self.__cmd_queue.get()
                      logging.debug(cmd)
                      self.socket.sendall(struct.pack("!I", len(cmd)) + str.encode(cmd))
          # send kill command, before disconnecting
          self.cmd_killsim()
          # disconnect
          self.disconnect()
          # if process still running, kill it
          self.__stop_application()
code_tokens: def run ( self ) : self . __start_application ( ) while ( not self . __start_instance or self . __p . poll ( ) is None ) and not self . __cancel . is_set ( ) : if not self . connected . is_set ( ) : self . connect ( ) else : length = struct . unpack ( "!I" , self . socket . recv ( 4 ) ) [ 0 ] msg = self . socket . recv ( length ) . decode ( ) sexp = sexpr . str2sexpr ( msg ) self . __update_environment ( sexp [ 0 ] ) self . __update_scene ( sexp [ 1 : ] ) if not self . __cmd_queue . empty ( ) : cmd = self . __cmd_queue . get ( ) logging . debug ( cmd ) self . socket . sendall ( struct . pack ( "!I" , len ( cmd ) ) + str . encode ( cmd ) ) self . cmd_killsim ( ) self . disconnect ( ) self . __stop_application ( )
short_docstring: The main method of this process.
short_docstring_tokens: The main method of this process .
comment: """The main method of this process. It starts the simspark application, connects to it and receives updates of
          the simulation state and also sends scheduled commands to the simulation."""$SEP$# connect to the simspark instance$SEP$# send scheduled (trainer) commands$SEP$# send kill command, before disconnecting$SEP$# disconnect$SEP$# if process still running, kill it