Message 82534 - Python tracker (original) (raw)

this occurs for me running on Mac OSX Leopard. The equivalent code using "processing" in python 2.5 works fine, which is how I found this bug - my code hung when upgraded to 2.6. Basically initiating a multiprocessing.Pool inside of multiprocessing.Process hangs the application. Below is code which illustrates the issue on both py2.6 and py3.0:

from multiprocessing import Pool, Process
import sys

def f(x):
    return x*x

def go():
    pool = Pool(processes=4)              
    x = pool.map(f, [1, 2, 3, 4, 5, 6, 7])
    sys.stdout.write("result: %s\n" % x)

def go2():
    x = map(f, [1,2,3,4,5,6,7])
    sys.stdout.write("result: %s\n" % x)

# pool alone, fine
go()

# process alone, fine
p = Process(target=go2)
p.start()
p.join()

# use both, hangs
p = Process(target=go)
p.start()
p.join()