Skip to content
Advertisement

Return value from function within a class using multiprocessing

I have following piece of codes, which I want to run through multiprocessing, I wonder how can I get return values after parallel processing is finished. I prefer not to make any change to getdata function.

JavaScript

Output:

JavaScript

Advertisement

Answer

The Calculation objects you create in your main process are copied into the spawned process, so there is no way to extract their state or get the return value of getdata without doing something explicit.

You could use a multiprocessing.Queue to store your results like so

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement