feat: put temperary file in the same directory as the destination file (#805)

This commit is contained in:
wozeparrot 2023-05-25 23:46:02 -04:00 committed by GitHub
parent 3ddcb5c36f
commit 7351eb4b61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 2 deletions

View File

@ -21,18 +21,19 @@ def fetch(url):
return f.read()
def download_file(url, fp, skip_if_exists=True):
import requests, os
import requests, os, pathlib
if skip_if_exists and os.path.isfile(fp) and os.stat(fp).st_size > 0:
return
r = requests.get(url, stream=True)
assert r.status_code == 200
progress_bar = tqdm(total=int(r.headers.get('content-length', 0)), unit='B', unit_scale=True, desc=url)
with tempfile.NamedTemporaryFile(delete=False) as f:
with tempfile.NamedTemporaryFile(dir=pathlib.Path(fp).parent, delete=False) as f:
for chunk in r.iter_content(chunk_size=16384):
progress_bar.update(f.write(chunk))
f.close()
os.rename(f.name, fp)
def my_unpickle(fb0):
key_prelookup = defaultdict(list)
def _rebuild_tensor_v2(storage, storage_offset, size, stride, requires_grad, backward_hooks, metadata=None):