From 39dab18307bb759d565a278f042c31f02815132c Mon Sep 17 00:00:00 2001 From: oobabooga <112222186+oobabooga@users.noreply.github.com> Date: Fri, 19 May 2023 11:19:34 -0300 Subject: [PATCH] Add a timeout to download-model.py requests --- download-model.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/download-model.py b/download-model.py index 1662b490..44b87a8c 100644 --- a/download-model.py +++ b/download-model.py @@ -98,7 +98,7 @@ def get_download_links_from_huggingface(model, branch, text_only=False): is_lora = False while True: url = f"{base}{page}" + (f"?cursor={cursor.decode()}" if cursor else "") - r = requests.get(url) + r = requests.get(url, timeout=10) r.raise_for_status() content = r.content @@ -169,7 +169,7 @@ def get_single_file(url, output_folder, start_from_scratch=False): output_path = output_folder / filename if output_path.exists() and not start_from_scratch: # Check if the file has already been downloaded completely - r = requests.get(url, stream=True) + r = requests.get(url, stream=True, timeout=10) total_size = int(r.headers.get('content-length', 0)) if output_path.stat().st_size >= total_size: return @@ -180,7 +180,7 @@ def get_single_file(url, output_folder, start_from_scratch=False): headers = {} mode = 'wb' - r = requests.get(url, stream=True, headers=headers) + r = requests.get(url, stream=True, headers=headers, timeout=10) with open(output_path, mode) as f: total_size = int(r.headers.get('content-length', 0)) block_size = 1024