marcoabreu commented on a change in pull request #11181: [MXNET-525] Add retry
logic to download functions to fix flaky tests
URL: https://github.com/apache/incubator-mxnet/pull/11181#discussion_r193910224
##########
File path: python/mxnet/gluon/utils.py
##########
@@ -200,26 +202,35 @@ def download(url, path=None, overwrite=False,
sha1_hash=None):
fname = os.path.join(path, url.split('/')[-1])
else:
fname = path
+ assert retries >= 0, "Number of retries should be at least 0"
if overwrite or not os.path.exists(fname) or (sha1_hash and not
check_sha1(fname, sha1_hash)):
dirname = os.path.dirname(os.path.abspath(os.path.expanduser(fname)))
if not os.path.exists(dirname):
os.makedirs(dirname)
-
- print('Downloading %s from %s...'%(fname, url))
- r = requests.get(url, stream=True)
- if r.status_code != 200:
- raise RuntimeError("Failed downloading url %s"%url)
- with open(fname, 'wb') as f:
- for chunk in r.iter_content(chunk_size=1024):
- if chunk: # filter out keep-alive new chunks
- f.write(chunk)
-
- if sha1_hash and not check_sha1(fname, sha1_hash):
- raise UserWarning('File {} is downloaded but the content hash does
not match. ' \
- 'The repo may be outdated or download may be
incomplete. ' \
- 'If the "repo_url" is overridden, consider
switching to ' \
- 'the default repo.'.format(fname))
+ while (retries+1 > 0):
+ try:
+ print('Downloading %s from %s...'%(fname, url))
+ r = requests.get(url, stream=True)
+ if r.status_code != 200:
+ raise RuntimeError("Failed downloading url %s"%url)
+ with open(fname, 'wb') as f:
+ for chunk in r.iter_content(chunk_size=1024):
+ if chunk: # filter out keep-alive new chunks
+ f.write(chunk)
+
+ if sha1_hash and not check_sha1(fname, sha1_hash):
+ raise UserWarning('File {} is downloaded but the content
hash does not match. ' \
+ 'The repo may be outdated or download
may be incomplete. ' \
+ 'If the "repo_url" is overridden,
consider switching to ' \
+ 'the default repo.'.format(fname))
+ break
+ except Exception as e:
Review comment:
Agree. We can add backoff if we deem it to be necessary. We're hitting big
webservers like S3, so it's rather just our connections getting dropped on the
way rather than actual server problems.
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
With regards,
Apache Git Services