Skip to content

Rich with multiprocessing.Pool.starmap() ? #884

Answered by willmcgugan
gatto asked this question in Q&A
Discussion options

You must be logged in to vote

I was mistaken about that callback. I thought it would be called for each result, but it seems to be called at the end with all results.

You can use imap which yields each result as they are calculated. The following works for me:

import time
import multiprocessing
from rich.progress import Progress


def do_kmeans(param1):
    time.sleep(5)    
    return param1

def call_do_kmeans(params):
    return do_kmeans(*params)

if __name__ == "__main__":
    algo_params = []
    results = []
    for x in range(100):
        algo_params.append([x])

    with Progress() as progress:
        task_id = progress.add_task("[cyan]Working...", total=len(algo_params))
        with multiprocessing.Pool(p…

Replies: 3 comments 3 replies

Comment options

You must be logged in to vote
1 reply
@gatto
Comment options

Comment options

You must be logged in to vote
1 reply
@gatto
Comment options

Comment options

You must be logged in to vote
1 reply
@gatto
Comment options

Answer selected by gatto
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants