Multiprocessing : use tqdm to display a progress bar

后端 未结 8 506
情深已故
情深已故 2020-12-04 07:26

To make my code more \"pythonic\" and faster, I use \"multiprocessing\" and a map function to send it a) the function and b) the range of iterations.

The implanted s

8条回答
  •  北荒
    北荒 (楼主)
    2020-12-04 07:50

    import multiprocessing as mp
    import tqdm
    
    
    some_iterable = ...
    
    def some_func():
        # your logic
        ...
    
    
    if __name__ == '__main__':
        with mp.Pool(mp.cpu_count()-2) as p:
            list(tqdm.tqdm(p.imap(some_func, iterable), total=len(iterable)))
    

提交回复
热议问题