Skip to content

Latest commit

 

History

History
27 lines (20 loc) · 640 Bytes

progress-bar-for-multiprocessing.md

File metadata and controls

27 lines (20 loc) · 640 Bytes

Progress Bar for Multiprocessing

Using tqdm.tqdm with multiprocessing.imap we can present to users a progress bar for parallel their computation.

import mulitprocessing as mp
from tqdm import tqdm

def process(data):
    result = data + 1
    return result

N = 100
data = [i for i in range(N)]
results = [] 

if __name__ == '__main__':
    with mp.Pool(mp.cpu_count()) as pool:
        results = list(tqdm(pool.imap(process, data), total=len(data)))
    for item in results:
        print(item)

References