def WaitUntilModelLoaded(self, deadline: float, polling_interval_sec: int) -> None: """Wait until model is loaded and available. Args: deadline: A deadline time in UTC timestamp (in seconds). polling_interval_sec: GetServingStatus() polling interval. Raises: DeadlineExceeded: When deadline exceeded before model is ready. ValidationFailed: If validation failed explicitly. """ while time.time() < deadline: status = self._GetServingStatus() if status == types.ModelServingStatus.NOT_READY: logging.log_every_n_seconds( level=logging.INFO, n_seconds=10, msg='Waiting for model to be loaded...') time.sleep(polling_interval_sec) continue elif status == types.ModelServingStatus.UNAVAILABLE: raise error_types.ValidationFailed( 'Model server failed to load the model.') else: logging.info('Model is successfully loaded.') return raise error_types.DeadlineExceeded( 'Deadline exceeded while waiting the model to be loaded.')
def SendRequests(self, requests: List[types.Request]) -> None: """Send requests to the model server. Args: requests: A list of request protos. Raises: ValidationFailed: If error occurred while sending requests. """ for r in requests: try: self._SendRequest(r) except Exception as e: # pylint: disable=broad-except raise error_types.ValidationFailed( f'Model server failed to respond to the request {r}') from e
def SendRequests(self, requests: List[types.Request]) -> None: """Send requests to the model server. Args: requests: A list of request protos. Raises: ValidationFailed: If error occurred while sending requests. """ for r in requests: try: self._SendRequest(r) except Exception as original_error: # pylint: disable=broad-except six.raise_from( error_types.ValidationFailed( 'Model server failed to respond to the request {}'. format(r)), original_error)