Skip to content

Commit

Permalink
Add timeout to requests calls (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
pixeeai committed Oct 1, 2024
1 parent cd6eeea commit 4f8c127
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion jax/_src/clusters/cloud_tpu_cluster.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_metadata(key):
while retry_count < 6:
api_resp = requests.get(
f'{gce_metadata_endpoint}/computeMetadata/v1/instance/attributes/{key}',
headers={'Metadata-Flavor': 'Google'})
headers={'Metadata-Flavor': 'Google'}, timeout=60)
if api_resp.status_code == 200:
break
retry_count += 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def serving_call_mnist(images):
# You can see the name of the input ("inputs") in the SavedModel dump.
data = f'{{"inputs": {images_json}}}'
predict_url = f"http://{_PREDICTION_SERVICE_ADDR.value}/v1/models/{_MODEL_SPEC_NAME.value}:predict"
response = requests.post(predict_url, data=data)
response = requests.post(predict_url, data=data, timeout=60)
if response.status_code != 200:
msg = (f"Received error response {response.status_code} from model "
f"server: {response.text}")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def download_dataset(dir_path, nb_classes):
continue
with open(cls_file_path, "wb") as save_file:
try:
response = requests.get(url + cls_filename.replace('_', ' '))
response = requests.get(url + cls_filename.replace('_', ' '), timeout=60)
save_file.write(response.content)
print(f'Successfully fetched {cls_filename}')
except:
Expand Down

0 comments on commit 4f8c127

Please sign in to comment.