url = "https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz" import httpx with httpx.stream("GET", url) asresponse: total = int(response.headers["Content-Length"]) with tqdm.tqdm(total=total) asprogress: for chunk in response.iter_bytes(): progress.update(len(chunk))
files = [f"vid-{i}.mp4" for i in range(4)] for fname in tqdm.tqdm(files, desc="files"): total = random.randrange(10**9, 2 * 10**9) with tqdm.tqdm(total=total, desc=fname) as progress: current = 0 while current < total: chunk_size = min(random.randrange(10**3, 10**5), total - current) current += chunk_size if random.uniform(0, 1) < 0.01: time.sleep(0.1) progress.update(chunk_size)