Make progress bars slightly smoother

This commit is contained in:
nathom 2021-04-13 21:29:07 -07:00
parent 44dc29d7e5
commit 208bae7b35

View file

@ -135,19 +135,18 @@ def tqdm_download(url: str, filepath: str, params: dict = None, desc: str = None
raise NonStreamable(url)
try:
with std_out_err_redirect_tqdm() as orig_stdout:
with open(filepath, "wb") as file, tqdm(
file=orig_stdout,
total=total,
unit="iB",
unit_scale=True,
unit_divisor=1024,
desc=desc,
dynamic_ncols=True,
) as bar:
for data in r.iter_content(chunk_size=1024):
size = file.write(data)
bar.update(size)
with open(filepath, "wb") as file, tqdm(
total=total,
unit="iB",
unit_scale=True,
unit_divisor=1024,
desc=desc,
dynamic_ncols=True,
# leave=False,
) as bar:
for data in r.iter_content(chunk_size=1024):
size = file.write(data)
bar.update(size)
except Exception:
try:
os.remove(filepath)