fetch() 'ran out of input' fix (#65)

If requests.get fails during a download, the incomplete file is passed
without a size check. This causes errors during image/model loading.
Not sure if this is a problem on all systems.
This commit is contained in:
Manjeet Singh 2020-11-07 23:15:10 +05:30 committed by GitHub
parent bc7758cc5b
commit 23c39d9f52
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 2 additions and 1 deletions

View File

@ -1,4 +1,5 @@
import numpy as np
import os
def mask_like(like, mask_inx, mask_value = 1.0):
mask = np.zeros_like(like).reshape(-1)
@ -12,7 +13,7 @@ def layer_init_uniform(*x):
def fetch(url):
import requests, os, hashlib, tempfile
fp = os.path.join(tempfile.gettempdir(), hashlib.md5(url.encode('utf-8')).hexdigest())
if os.path.isfile(fp):
if os.path.isfile(fp) and os.stat(fp).st_size > 0:
with open(fp, "rb") as f:
dat = f.read()
else: