Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 029ecea

Browse filesBrowse files
gh-134262: Add retries to downloads in PCbuild\get_external.py (GH-134820)
(cherry picked from commit e9d845b) Co-authored-by: Emma Smith <emma@emmatyping.dev>
1 parent dcfb229 commit 029ecea
Copy full SHA for 029ecea

1 file changed

+21-2Lines changed: 21 additions & 2 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎PCbuild/get_external.py‎

Copy file name to clipboardExpand all lines: PCbuild/get_external.py
+21-2Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,36 @@
99
from urllib.request import urlretrieve
1010

1111

12+
def retrieve_with_retries(download_location, output_path, reporthook,
13+
max_retries=7):
14+
"""Download a file with exponential backoff retry and save to disk."""
15+
for attempt in range(max_retries):
16+
try:
17+
resp = urlretrieve(
18+
download_location,
19+
output_path,
20+
reporthook=reporthook,
21+
)
22+
except ConnectionError as ex:
23+
if attempt == max_retries:
24+
msg = f"Download from {download_location} failed."
25+
raise OSError(msg) from ex
26+
time.sleep(2.25**attempt)
27+
else:
28+
return resp
29+
30+
1231
def fetch_zip(commit_hash, zip_dir, *, org='python', binary=False, verbose):
1332
repo = f'cpython-{"bin" if binary else "source"}-deps'
1433
url = f'https://github.com/{org}/{repo}/archive/{commit_hash}.zip'
1534
reporthook = None
1635
if verbose:
1736
reporthook = print
1837
zip_dir.mkdir(parents=True, exist_ok=True)
19-
filename, headers = urlretrieve(
38+
filename, _headers = retrieve_with_retries(
2039
url,
2140
zip_dir / f'{commit_hash}.zip',
22-
reporthook=reporthook,
41+
reporthook
2342
)
2443
return filename
2544

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.