mirror of https://github.com/commaai/tinygrad.git
feat: put temperary file in the same directory as the destination file (#805)
This commit is contained in:
parent
3ddcb5c36f
commit
7351eb4b61
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue