Skip to content

Commit 0760043

Browse files
authored
Add retry when download dataset (#5098)
1 parent 56b723c commit 0760043

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

python/paddle/v2/dataset/common.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,14 @@ def download(url, module_name, md5sum):
6565
os.makedirs(dirname)
6666

6767
filename = os.path.join(dirname, url.split('/')[-1])
68-
if not (os.path.exists(filename) and md5file(filename) == md5sum):
68+
retry = 0
69+
retry_limit = 3
70+
while not (os.path.exists(filename) and md5file(filename) == md5sum):
71+
if retry < retry_limit:
72+
retry += 1
73+
else:
74+
raise RuntimeError("Cannot download {0} within retry limit {2}".
75+
format(url, retry_limit))
6976
print "Cache file %s not found, downloading %s" % (filename, url)
7077
r = requests.get(url, stream=True)
7178
total_length = r.headers.get('content-length')

0 commit comments

Comments
 (0)