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) raise NonStreamable(url)
try: try:
with std_out_err_redirect_tqdm() as orig_stdout: with open(filepath, "wb") as file, tqdm(
with open(filepath, "wb") as file, tqdm( total=total,
file=orig_stdout, unit="iB",
total=total, unit_scale=True,
unit="iB", unit_divisor=1024,
unit_scale=True, desc=desc,
unit_divisor=1024, dynamic_ncols=True,
desc=desc, # leave=False,
dynamic_ncols=True, ) as bar:
) as bar: for data in r.iter_content(chunk_size=1024):
for data in r.iter_content(chunk_size=1024): size = file.write(data)
size = file.write(data) bar.update(size)
bar.update(size)
except Exception: except Exception:
try: try:
os.remove(filepath) os.remove(filepath)