1

I tried to use multiprocessing for a simple code in windows 10, python2.7 and jupyter notebook. When I run the code the kernel got stack without any errors thrown. I checked the task manager for performance and saw 8 (the number of cores in my CPU) processes running with 0% use of the CPU for each and everyone of them. I looked almost everywhere but didn't find anything. I also tried it in the anaconda prompt but got endless loop of errors.

Here is my code:

import multiprocessing

n_cpu = multiprocessing.cpu_count()

def foo(x):
    return x**2

if __name__ == '__main__':
    pool = multiprocessing.Pool(processes = n_cpu)
    res = pool.map(foo, [1,2,3])  
    pool.close() 
pkz
  • 41
  • 7

1 Answers1

0

Is this your actual code? With foo being so simple, this code will run so quickly that it's likely to look like 0% CPU usage.

If you see that there are sub-processes spawned, then pool.map is doing it's job. If you want to see that all of them actually use full CPU, give them some real meat to chew on (maybe something like sum([sum(range(x)) for x in range(1000)]).

Gordon Bean
  • 4,272
  • 1
  • 32
  • 47
  • This is not the problem. Even when I give it range(1000000) the kernel got stacked and I get no out. – pkz May 11 '18 at 04:21