未验证 提交 1ef23279 编写于 作者: W Wenyu 提交者: GitHub

Fix retry error in download when exception occurs (#32816)

* fix retry in download when exception occurs
上级 84eca16d
...@@ -70,6 +70,13 @@ class TestDownload(unittest.TestCase): ...@@ -70,6 +70,13 @@ class TestDownload(unittest.TestCase):
for url in urls: for url in urls:
get_path_from_url(url, root_dir='./test') get_path_from_url(url, root_dir='./test')
def test_retry_exception(self, ):
with self.assertRaises(RuntimeError):
from paddle.utils.download import _download
_download(
'www.baidu.com',
'./test', )
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()
...@@ -186,7 +186,15 @@ def _download(url, path, md5sum=None): ...@@ -186,7 +186,15 @@ def _download(url, path, md5sum=None):
logger.info("Downloading {} from {}".format(fname, url)) logger.info("Downloading {} from {}".format(fname, url))
try:
req = requests.get(url, stream=True) req = requests.get(url, stream=True)
except Exception as e: # requests.exceptions.ConnectionError
logger.info(
"Downloading {} from {} failed {} times with exception {}".
format(fname, url, retry_cnt + 1, str(e)))
time.sleep(1)
continue
if req.status_code != 200: if req.status_code != 200:
raise RuntimeError("Downloading from {} failed with code " raise RuntimeError("Downloading from {} failed with code "
"{}!".format(url, req.status_code)) "{}!".format(url, req.status_code))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册