MCPcopy Index your code
hub / github.com/python/cpython / retrieve_with_retries

Function retrieve_with_retries

PCbuild/get_external.py:38–54  ·  view source on GitHub ↗

Download a file with exponential backoff retry and save to disk.

(download_location, output_path, reporthook,
                          max_retries=7)

Source from the content-addressed store, hash-verified

36
37
38def retrieve_with_retries(download_location, output_path, reporthook,
39 max_retries=7):
40 """Download a file with exponential backoff retry and save to disk."""
41 for attempt in range(max_retries + 1):
42 try:
43 resp = urllib.request.urlretrieve(
44 download_location,
45 output_path,
46 reporthook=reporthook,
47 )
48 except (urllib.error.URLError, ConnectionError) as ex:
49 if attempt == max_retries:
50 raise OSError(f'Download from {download_location} failed.') from ex
51 trigger_automatic_root_certificate_update(download_location)
52 time.sleep(2.25**attempt)
53 else:
54 return resp
55
56def fetch_zip(commit_hash, zip_dir, *, org='python', binary=False, verbose):
57 repo = 'cpython-bin-deps' if binary else 'cpython-source-deps'

Callers 2

fetch_zipFunction · 0.85
fetch_releaseFunction · 0.85

Calls 3

urlretrieveMethod · 0.80
sleepMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…