Skip to content

gh-134262: Add retries to downloads in PCbuild\get_external.py #134820

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 4 commits into from
May 28, 2025
Merged
Changes from all commits
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
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:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because attempt comes from range(max_retries), this condition can never be hit.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♀️ thanks for catching that, opened #134867

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