Skip to content

Commit 89d29a5

Browse files
committed
pythonbuild: sleep before retrying download
A temporal backoff is a best practice.
1 parent 40ca5c7 commit 89d29a5

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

pythonbuild/utils.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import subprocess
1616
import sys
1717
import tarfile
18+
import time
1819
import zipfile
1920
import urllib.error
2021
import urllib.request
@@ -256,7 +257,7 @@ def download_to_path(url: str, path: pathlib.Path, size: int, sha256: str):
256257

257258
tmp = path.with_name("%s.tmp" % path.name)
258259

259-
for _ in range(5):
260+
for attempt in range(5):
260261
try:
261262
try:
262263
with tmp.open("wb") as fh:
@@ -269,8 +270,10 @@ def download_to_path(url: str, path: pathlib.Path, size: int, sha256: str):
269270
raise
270271
except http.client.HTTPException as e:
271272
print("HTTP exception; retrying: %s" % e)
273+
time.sleep(2 ** attempt)
272274
except urllib.error.URLError as e:
273275
print("urllib error; retrying: %s" % e)
276+
time.sleep(2 ** attempt)
274277
else:
275278
raise Exception("download failed after multiple retries")
276279

0 commit comments

Comments
 (0)