Python2.5 multiprocessing pool

I have python2.5 and multiprocessing (get from http://code.google.com/p/python-multiprocessing/ )

This simple code (getting from documents) works very strange from time to time, sometimes it’s fine, but sometimes it starts ex timeout or hangs on my Windows (Vista), only reset helps :) Why can this happen?

from multiprocessing import Pool def f(x): print "fc",x return x*x pool = Pool(processes=4) if __name__ == '__main__': result = pool.apply_async(f, (10,)) # evaluate "f(10)" asynchronously print result.get(timeout=3) # prints "100" unless your computer is *very* slow 
+1
source share
1 answer

This is just a wild hunch, but have you tried moving the Pool creation to an if block? I suspect that otherwise, it could spawn an unlimited number of new processes, causing freezing.

+4
source

Source: https://habr.com/ru/post/1397239/


All Articles