def close(self):
        """gym api close"""
        try:
            # Purge last token from head node with <Close> message.
            sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            sock.connect((self.server, self.port))
            self._hello(sock)

            comms.send_message(sock, ("<Close>" + self._get_token() + "</Close>").encode())
            reply = comms.recv_message(sock)
            ok, = struct.unpack('!I', reply)
            assert ok
            sock.close()
        except Exception as e:
            self._log_error(e)
        if self.client_socket:
            self.client_socket.close()
            self.client_socket = None
def close ( self ) : try : sock = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) sock . connect ( ( self . server , self . port ) ) self . _hello ( sock ) comms . send_message ( sock , ( "<Close>" + self . _get_token ( ) + "</Close>" ) . encode ( ) ) reply = comms . recv_message ( sock ) ok , = struct . unpack ( '!I' , reply ) assert ok sock . close ( ) except Exception as e : self . _log_error ( e ) if self . client_socket : self . client_socket . close ( ) self . client_socket = None
gym api close