提交 a80e912a 编写于 作者: K Kaipeng Deng 提交者: GitHub

refine weight download (#3071)

* refine weight download

* fix comment
上级 3139f153
......@@ -213,8 +213,12 @@ def _download(url, path, md5sum=None):
raise RuntimeError("Downloading from {} failed with code "
"{}!".format(url, req.status_code))
# For protecting download interupted, download to
# tmp_fullname firstly, move tmp_fullname to fullname
# after download finished
tmp_fullname = fullname + "_tmp"
total_size = req.headers.get('content-length')
with open(fullname, 'wb') as f:
with open(tmp_fullname, 'wb') as f:
if total_size:
for chunk in tqdm.tqdm(
req.iter_content(chunk_size=1024),
......@@ -225,6 +229,7 @@ def _download(url, path, md5sum=None):
for chunk in req.iter_content(chunk_size=1024):
if chunk:
f.write(chunk)
shutil.move(tmp_fullname, fullname)
return fullname
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册