Created
July 10, 2021 13:33
-
-
Save cccntu/008089ebdd4a98a0ac8e2f1317b05007 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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