Why is multiprocessing.starmap() taking so long on a dummy function?

41 Views Asked by At

Edit

Running this in a regular .py file helped. Note in the original question, I was running this in a .ipynb file.

Original Question

I am incredibly new to the world of Multiprocessing in Python.

As an experiment, I wrote the following code to see the benefits of multiprocessing. Specifically, I wanted to experiment with the starmap() functionality.

I wrote the following code:

from multiprocessing import Pool

def add(x, y):
    return x + y

with Pool(processes=4) as pool:
    input_data = [(1, 2), (3, 4), (5, 6)]
    result = pool.starmap(add, input_data)
    print(list(result))  # Output: [3, 7, 11]

This code is taking a really long time to execute. It's still running and it's been about 11mins.

My desktop has 8 cores, and 16 logical processors. It's an Intel(R) Core(TM) i7-10700 CPU @ 2.90GHz.

Python version: 3.10.7

OS - Windows 10

Running it in a Python Notebook in VS Code

Any thoughts?

0

There are 0 best solutions below