[python] tqdm

spring·2024년 4월 11일
0

while과 같이 tqdm 사용하기

from tqdm import tqdm

def func(a, b):
    return a * b

r = []
with tqdm(total=100) as pbar:
    i = 0
    while True:
        r.append(func(i, i * i))
        pbar.update(1)
        i += 1
        if i == 100:
            break

ThreadPoolExecutor와 같이 tqdm 사용하기

from concurrent.futures import ThreadPoolExecutor
from tqdm import tqdm

def func(a, b):
    return a * b

params = []
for i in range(100):
    params.append((i, i * i))
with ThreadPoolExecutor(max_workers=4) as pool:
    r = list(tqdm(pool.map(lambda e: func(*e), params), total=len(params)))

print(r)


References

profile
Researcher & Developer @ NAVER Corp | Designer @ HONGIK Univ.

0개의 댓글