shim: retry downloads on transient network errors (#41)
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
"""Shim setup.py: downloads pre-built wheels from GitHub Releases at install time."""
|
"""Shim setup.py: downloads pre-built wheels from GitHub Releases at install time."""
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
|
import time
|
||||||
import zipfile
|
import zipfile
|
||||||
from io import BytesIO
|
from io import BytesIO
|
||||||
|
from urllib.error import URLError
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -45,7 +47,16 @@ class InstallPrebuilt(build_py):
|
|||||||
url = f"{REPO_URL}/releases/download/{TAG}/{whl_name}"
|
url = f"{REPO_URL}/releases/download/{TAG}/{whl_name}"
|
||||||
|
|
||||||
print(f"Downloading {url} ...")
|
print(f"Downloading {url} ...")
|
||||||
raw = urlopen(url).read()
|
for attempt in range(3):
|
||||||
|
try:
|
||||||
|
raw = urlopen(url, timeout=60).read()
|
||||||
|
break
|
||||||
|
except (URLError, OSError) as e:
|
||||||
|
if attempt == 2:
|
||||||
|
raise
|
||||||
|
wait = 2 ** attempt
|
||||||
|
print(f"Download failed ({e}), retrying in {wait}s ...")
|
||||||
|
time.sleep(wait)
|
||||||
|
|
||||||
print(f"Extracting {DATADIR} ...")
|
print(f"Extracting {DATADIR} ...")
|
||||||
with zipfile.ZipFile(BytesIO(raw)) as zf:
|
with zipfile.ZipFile(BytesIO(raw)) as zf:
|
||||||
|
|||||||
Reference in New Issue
Block a user