mirror of
https://github.com/python/cpython.git
synced 2025-07-07 19:35:27 +00:00
gh-134262: increase retries in Tools/build/generate_sbom.py
(#134558)
This commit is contained in:
parent
9b5e80000e
commit
3f9eb55e09
1 changed files with 7 additions and 4 deletions
|
@ -4,6 +4,7 @@ import glob
|
|||
import hashlib
|
||||
import json
|
||||
import os
|
||||
import random
|
||||
import re
|
||||
import subprocess
|
||||
import sys
|
||||
|
@ -164,16 +165,18 @@ def get_externals() -> list[str]:
|
|||
|
||||
|
||||
def download_with_retries(download_location: str,
|
||||
max_retries: int = 5,
|
||||
base_delay: float = 2.0) -> typing.Any:
|
||||
max_retries: int = 7,
|
||||
base_delay: float = 2.25,
|
||||
max_jitter: float = 1.0) -> typing.Any:
|
||||
"""Download a file with exponential backoff retry."""
|
||||
for attempt in range(max_retries):
|
||||
try:
|
||||
resp = urllib.request.urlopen(download_location)
|
||||
except urllib.error.URLError as ex:
|
||||
if attempt == max_retries:
|
||||
raise ex
|
||||
time.sleep(base_delay**attempt)
|
||||
msg = f"Download from {download_location} failed."
|
||||
raise OSError(msg) from ex
|
||||
time.sleep(base_delay**attempt + random.uniform(0, max_jitter))
|
||||
else:
|
||||
return resp
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue