Apply a method to a list of objects in parallel using multi-processing

后端 未结 5 879
夕颜
夕颜 2021-01-01 18:58

I have created a class with a number of methods. One of the methods is very time consuming, my_process, and I\'d like to do that method in parallel. I came acro

5条回答
  •  别那么骄傲
    2021-01-01 19:58

    Generally the easiest way to run the same calculation in parallel is the map method of a multiprocessing.Pool (or the as_completed function from concurrent.futures in Python 3).

    However, the map method applies a function that only takes one argument to an iterable of data using multiple processes.

    So this function cannot be a normal method, because that requires at least two arguments; it must also include self! It could be a staticmethod, however. See also this answer for a more in-depth explanation.

提交回复
热议问题