multiprocessing.Pool: When to use apply, apply_async or map?

后端 未结 3 2164
遥遥无期
遥遥无期 2020-11-22 15:45

I have not seen clear examples with use-cases for Pool.apply, Pool.apply_async and Pool.map. I am mainly using Pool.map; what are the advantages of others?

3条回答
  •  自闭症患者
    2020-11-22 16:16

    Regarding apply vs map:

    pool.apply(f, args): f is only executed in ONE of the workers of the pool. So ONE of the processes in the pool will run f(args).

    pool.map(f, iterable): This method chops the iterable into a number of chunks which it submits to the process pool as separate tasks. So you take advantage of all the processes in the pool.

提交回复
热议问题