Skip to content

Instantly share code, notes, and snippets.

@cccntu
Created July 10, 2021 13:33
Show Gist options
  • Save cccntu/008089ebdd4a98a0ac8e2f1317b05007 to your computer and use it in GitHub Desktop.
Save cccntu/008089ebdd4a98a0ac8e2f1317b05007 to your computer and use it in GitHub Desktop.
from tqdm.auto import tqdm
import time
class LengthedGeneratorWrapper:
"""wraps an infinite generator with length for tqdm"""
def __init__(self, infinite_generator, len):
self.generator = infinite_generator
self.len = len
def __len__(self):
return self.len
def __iter__(self):
for _ in range(self.len):
yield next(self.generator)
def gen():
while True:
yield 0
g = gen()
dl = CustomSizeLoader(g, 1000)
for i in tqdm(dl):
time.sleep(0.1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment