Skip to content

[3.14] gh-134262: Add retries to downloads in PCbuild\get_external.py (GH-134820) #134865

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 28, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
gh-134262: Add retries to downloads in PCbuild\get_external.py (GH-13…
…4820)

(cherry picked from commit e9d845b)

Co-authored-by: Emma Smith <emma@emmatyping.dev>
  • Loading branch information
emmatyping authored and miss-islington committed May 28, 2025
commit d6e484497688b69560f0cbdb06bcbc18f02250b8
23 changes: 21 additions & 2 deletions PCbuild/get_external.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,36 @@
from urllib.request import urlretrieve


def retrieve_with_retries(download_location, output_path, reporthook,
max_retries=7):
"""Download a file with exponential backoff retry and save to disk."""
for attempt in range(max_retries):
try:
resp = urlretrieve(
download_location,
output_path,
reporthook=reporthook,
)
except ConnectionError as ex:
if attempt == max_retries:
msg = f"Download from {download_location} failed."
raise OSError(msg) from ex
time.sleep(2.25**attempt)
else:
return resp


def fetch_zip(commit_hash, zip_dir, *, org='python', binary=False, verbose):
repo = f'cpython-{"bin" if binary else "source"}-deps'
url = f'https://github.com/{org}/{repo}/archive/{commit_hash}.zip'
reporthook = None
if verbose:
reporthook = print
zip_dir.mkdir(parents=True, exist_ok=True)
filename, headers = urlretrieve(
filename, _headers = retrieve_with_retries(
url,
zip_dir / f'{commit_hash}.zip',
reporthook=reporthook,
reporthook
)
return filename

Expand Down
Loading