From 8270d43c0dccca29739d2aee7db782ec2ae7e803 Mon Sep 17 00:00:00 2001 From: rayair250-droid Date: Thu, 23 Jul 2026 23:37:50 +0200 Subject: [PATCH] Add timeouts to model-download HTTP requests Two requests.get() calls that download model files had no timeout, so a stalled or unresponsive server hangs the process indefinitely: - model_cls.py: downloading a model from a link - torchani_interface.py: fetching the ANI-1xnr parameters zip Add timeout=30, consistent with the rest of the codebase, which already sets timeouts on its network calls (MLatom.py, _update_check.py, _version.py). requests' timeout is a per-read inactivity limit, not a total cap, so it does not abort slow-but-progressing streamed downloads. --- mlatom/interfaces/torchani_interface.py | 2 +- mlatom/model_cls.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/mlatom/interfaces/torchani_interface.py b/mlatom/interfaces/torchani_interface.py index 445abc0..7f02e8b 100644 --- a/mlatom/interfaces/torchani_interface.py +++ b/mlatom/interfaces/torchani_interface.py @@ -1934,7 +1934,7 @@ def parse_ani1xnr_resources(): if not os.path.exists(local_dir+'ani-1xnr-main'): os.makedirs(local_dir, exist_ok=True) print(f'Downloading ANI-1xnr model parameters ...') - resource_res = requests.get(url) + resource_res = requests.get(url, timeout=30) resource_zip = zipfile.ZipFile(io.BytesIO(resource_res.content)) resource_zip.extractall(local_dir) return local_dir diff --git a/mlatom/model_cls.py b/mlatom/model_cls.py index 99177db..d9f89f7 100644 --- a/mlatom/model_cls.py +++ b/mlatom/model_cls.py @@ -284,7 +284,7 @@ def _download(self, link=None, headers=None, target=None): assert target is not None, "Please provide target directory to be downloaded" print(f'Start downloading model from {link} to {target}'); sys.stdout.flush() try: - response = requests.get(link, headers=headers, stream=True, allow_redirects=True) + response = requests.get(link, headers=headers, stream=True, allow_redirects=True, timeout=30) total_size = int(response.headers.get("content-length", 0)) target += '.temp'