You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mxnet.apache.org by GitBox <gi...@apache.org> on 2018/06/07 22:33:50 UTC

[GitHub] ThomasDelteil commented on a change in pull request #11181: [MXNET-525] Add retry logic to download functions to fix flaky tests

ThomasDelteil 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_r193908119
 
 

 ##########
 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:
   I think for this version we can keep it stupid simple. Kellen has a more involved version in the works. From the error I have seen due to download, ConnectionReset, TLS handshakes aborted,  connection dropped, this should be enough. Happy to revisit if it proves incomplete.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services