import tqdm iterator = tqdm.tqdm(range(100000000)) for f in iterator: if f > 100000000/4: iterator.close() break