Problem with multiprocessing
Peter Otten
__peter__ at web.de
Wed Sep 2 04:51:05 EDT 2009
tleeuwenburg at gmail.com wrote:
> I have a problem using multiprocessing in a simple way. I created a
> file, testmp.py, with the following contents:
>
> ---------------------------------------------------
> import multiprocessing as mp
>
> p = mp.Pool(5)
>
> def f(x):
> return x * x
>
> print map(f, [1,2,3,4,5])
> print p.map(f, [1,2,3,4,5])
>
> ----------------------------------------------------
>
> I'm using 2.6 r26:66713, so not quite bleeding edge.
>
> If I run 'python2.6 testmp.py' I get errors of exactly the kind
> mentioned on docs.python.org for when multiprocessing is run using the
> interactive interpreter. However, I'm obviously *not* running the
> interactive interpreter.
>
> Any suggestions?
I'm too lazy to read the docs, so I just tinkered:
import multiprocessing as mp
import testmp
p = mp.Pool(5)
def f(x):
return x * x
if __name__ == "__main__":
print map(f, [1,2,3,4,5])
print p.map(testmp.f, [1,2,3,4,5])
More information about the Python-list
mailing list