in src/huggingface_hub/_inference_endpoints.py [0:0]
def wait(self, timeout: Optional[int] = None, refresh_every: int = 5) -> "InferenceEndpoint":
"""Wait for the Inference Endpoint to be deployed.
Information from the server will be fetched every 1s. If the Inference Endpoint is not deployed after `timeout`
seconds, a [`InferenceEndpointTimeoutError`] will be raised. The [`InferenceEndpoint`] will be mutated in place with the latest
data.
Args:
timeout (`int`, *optional*):
The maximum time to wait for the Inference Endpoint to be deployed, in seconds. If `None`, will wait
indefinitely.
refresh_every (`int`, *optional*):
The time to wait between each fetch of the Inference Endpoint status, in seconds. Defaults to 5s.
Returns:
[`InferenceEndpoint`]: the same Inference Endpoint, mutated in place with the latest data.
Raises:
[`InferenceEndpointError`]
If the Inference Endpoint ended up in a failed state.
[`InferenceEndpointTimeoutError`]
If the Inference Endpoint is not deployed after `timeout` seconds.
"""
if timeout is not None and timeout < 0:
raise ValueError("`timeout` cannot be negative.")
if refresh_every <= 0:
raise ValueError("`refresh_every` must be positive.")
start = time.time()
while True:
if self.status == InferenceEndpointStatus.FAILED:
raise InferenceEndpointError(
f"Inference Endpoint {self.name} failed to deploy. Please check the logs for more information."
)
if self.status == InferenceEndpointStatus.UPDATE_FAILED:
raise InferenceEndpointError(
f"Inference Endpoint {self.name} failed to update. Please check the logs for more information."
)
if self.status == InferenceEndpointStatus.RUNNING and self.url is not None:
# Verify the endpoint is actually reachable
_health_url = f"{self.url.rstrip('/')}/{self.health_route.lstrip('/')}"
response = get_session().get(_health_url, headers=self._api._build_hf_headers(token=self._token))
if response.status_code == 200:
logger.info("Inference Endpoint is ready to be used.")
return self
if timeout is not None:
if time.time() - start > timeout:
raise InferenceEndpointTimeoutError("Timeout while waiting for Inference Endpoint to be deployed.")
logger.info(f"Inference Endpoint is not deployed yet ({self.status}). Waiting {refresh_every}s...")
time.sleep(refresh_every)
self.fetch()