pythonbeginner

Multiprocessing Pool

Advanced Python pattern: multiprocessing-pool

python
from multiprocessing import Pool

def square(x: int) -> int:
    return x * x

if __name__ == '__main__':
    with Pool(processes=4) as pool:
        print(pool.map(square, [1,2,3,4,5]))

Use Cases

  • advanced programming
  • patterns

Tags

Related Snippets

Similar patterns you can reuse in the same workflow.