Download a file with exponential backoff retry and save to disk.
(download_location, output_path, reporthook,
max_retries=7)
| 36 | |
| 37 | |
| 38 | def 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 | |
| 56 | def fetch_zip(commit_hash, zip_dir, *, org='python', binary=False, verbose): |
| 57 | repo = 'cpython-bin-deps' if binary else 'cpython-source-deps' |
no test coverage detected
searching dependent graphs…