python pool doesn't work

Viewed 3643

I'm trying to use multithreading and in order to keep it simple at first, i'm running the following code:

import multiprocessing as mp

pool = mp.Pool(4)

def square(x):

    return x**2

results=pool.map(square,range(1,20))

As i understand, results should be a list containig the squares from 1 to 20. However, the code does not seem to terminate.(doing the same without pool finishes in a blink, this ran for several minutes, before i stopped it manually).

Additional information: task manager tells me, that the additional python processes have been launched and are running, but are using zero % of my cpu; still other unrelated processes like firefox skyrocket in their cpu usage, while the programm is running. I'm using windows 8 and a i5-4300U cpu (pooling to 2 instead of 4 doesn't help either)

What am i doing wrong? Are there any good ressources on the Pool class, which could help me understand what is wrong with my code?

2 Answers
Related