무거운 프로세스 몇 개의 진행상황이 알고 싶을때는 tqdm-multiprocess 패키지를 써야 속도 저하 없이 진행 상태를 확인할 수 있다.
from tqdm_multiprocess import TqdmMultiProcessPool
count = 10 # number of iteration in process
def process(n1, n2, tqdm_func, global_tqdm):
with tqdm_func(total=count) as progress:
for i in range(count):
# do something
progress.update()
global_progress.update()
def on_error(result):
pass
def on_done(result):
pass
if __name__=="__main__":
params = [(1,2),...]
total = count * len(params) # number of total iteration
pool = TqdmMultiProcessPool()
with tqdm(total=total) as global_progress:
global_progress.set_description("total")
tasks = [(process, params[i]) for i in range(len(params))]
pool.map(global_progress, tasks, on_error, on_done)
위 코드는 잦은 출력 때문에 속도가 느려질 수 있으므로 global_progress.update(1000)
등으로 보완해주는 것이 좋다.
참고: 작은 process들을 많이 실행할 때
Multiprocessing Pool과 함꼐 tqdm 사용하기 - 전지적 송윤섭시점 TIL