I am trying o solve a task of multiprocessing in Python.
I can achieve his task with he help of multiprocess
module but can't apply the same with multiprocessing
module. I have to apply with multiprocessing module cause I need to use freeze_support()
.
First I thought that the issue is with my code and post this, which haven't received any answers yet. Then I thought to run a toy example of applying multiprocessing
module to see whether I can figure out why multiprocessing doesn't run on my system. So I ran this code which I got from this tutorial.
import multiprocessing
import time
def cpu_bound(number):
return sum(i * i for i in range(number))
def find_sums(numbers):
with multiprocessing.Pool() as pool:
pool.map(cpu_bound, numbers)
if __name__ == "__main__":
numbers = [5_000_000 + x for x in range(20)]
start_time = time.time()
find_sums(numbers)
duration = time.time() - start_time
print(f"Duration {duration} seconds")
It seems that multiprocessing
module doesn't run on my machine, cause this toy example won't run on my system either.
When I apply multiprocess
module on this toy example, the results showed up in no time with utilizing all of my cores.
So I am wondering if the issue is with a specific configuration on my system or is there any equivalent of freeze_support()
in multiprocess
module?
By saying "this module won't run on my system", I mean that processes have spawned but the cpu won't go up and it seems that nothing is going on... after almost 10 minutes I manually terminate the run. But with multiprocess module the code completed in under 1 minute.
Thanks in advance.
PS: My machine has 4 cores.