Skip to content

Commit 211702b

Browse files
committed
urlcache: Retry 5 times when downloading blocks
Signed-off-by: Hector Martin <[email protected]>
1 parent e8c82fd commit 211702b

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

src/urlcache.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# SPDX-License-Identifier: MIT
2-
import os, sys, os.path
2+
import os, sys, os.path, time
33
from dataclasses import dataclass
44

55
from urllib import request
@@ -58,14 +58,16 @@ def get_block(self, blk):
5858
size += self.BLOCKSIZE
5959

6060
size = min(off + size, self.size) - off
61-
for retry in range(6):
61+
retries = 5
62+
for retry in range(retries + 1):
6263
try:
6364
data = self.get_partial(off, size)
6465
except Exception as e:
65-
if retry == 5:
66+
if retry == retries:
6667
print(f"Exceeded maximum retries downloading data.")
6768
sys.exit(1)
68-
print(f"Error downloading data ({e}), retrying... ({retry + 1}/5)")
69+
print(f"Error downloading data ({e}), retrying... ({retry + 1}/{retries})")
70+
time.sleep(1)
6971
else:
7072
break
7173

0 commit comments

Comments
 (0)