def wait_for_commands(self): logger.info("Python Server ready to receive messages") reset = False authenticated = self.python_parameters.auth_token is None try: while True: command = smart_decode(self.stream.readline())[:-1] if not authenticated: # Will raise an exception if auth fails in any way. authenticated = do_client_auth( command, self.stream, self.socket, self.python_parameters.auth_token) continue obj_id = smart_decode(self.stream.readline())[:-1] logger.info("Received command {0} on object id {1}".format( command, obj_id)) if obj_id is None or len(obj_id.strip()) == 0: break if command == proto.CALL_PROXY_COMMAND_NAME: return_message = self._call_proxy(obj_id, self.stream) self.socket.sendall(return_message.encode("utf-8")) elif command == proto.GARBAGE_COLLECT_PROXY_COMMAND_NAME: self.stream.readline() del (self.pool[obj_id]) self.socket.sendall( proto.SUCCESS_RETURN_MESSAGE.encode("utf-8")) else: logger.error("Unknown command {0}".format(command)) # We're sending something to prevent blocking, but at this # point, the protocol is broken. self.socket.sendall( proto.ERROR_RETURN_MESSAGE.encode("utf-8")) except Py4JAuthenticationError: reset = True logger.exception("Could not authenticate connection.") except socket.timeout: reset = True logger.info( "Timeout while python server was waiting for" "a message", exc_info=True) except Exception: # This is a normal exception... logger.info( "Error while python server was waiting for" "a message", exc_info=True) self.close(reset)
def wait_for_commands(self): logger.info("Python Server ready to receive messages") reset = False authenticated = self.python_parameters.auth_token is None try: while True: command = smart_decode(self.stream.readline())[:-1] if not authenticated: # Will raise an exception if auth fails in any way. authenticated = do_client_auth( command, self.stream, self.socket, self.python_parameters.auth_token) continue obj_id = smart_decode(self.stream.readline())[:-1] logger.info( "Received command {0} on object id {1}". format(command, obj_id)) if obj_id is None or len(obj_id.strip()) == 0: break if command == proto.CALL_PROXY_COMMAND_NAME: return_message = self._call_proxy(obj_id, self.stream) self.socket.sendall(return_message.encode("utf-8")) elif command == proto.GARBAGE_COLLECT_PROXY_COMMAND_NAME: self.stream.readline() _garbage_collect_proxy(self.pool, obj_id) self.socket.sendall( proto.SUCCESS_RETURN_MESSAGE.encode("utf-8")) else: logger.error("Unknown command {0}".format(command)) # We're sending something to prevent blocking, but at this # point, the protocol is broken. self.socket.sendall( proto.ERROR_RETURN_MESSAGE.encode("utf-8")) except Py4JAuthenticationError: reset = True logger.exception("Could not authenticate connection.") except socket.timeout: reset = True logger.info( "Timeout while python server was waiting for" "a message", exc_info=True) except Exception: # This is a normal exception... logger.info( "Error while python server was waiting for" "a message", exc_info=True) self.close(reset)