Search code examples
pythonparallel-processingmultiprocessingpoolpython-multithreading

Python multiprocessing pool for parallel processing


I want to execute some processes in parallel and wait until they finish. So I wrote this code:

pool = mp.Pool(5)
for a in table:
    pool.apply(func, args = (some_args))
pool.close()
pool.join()

Will I get 5 processes executing func in parallel here? Or the only option is apply_async?


Solution

  • The docs are quite clear on this: each call to apply blocks until the result is ready. Use apply_async.