python2.5 multiprocessing Pool

天涯浪子 提交于 2020-01-23 16:51:06

问题


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

This simple code (get from docs), works very strange from time to time, sometimes it ok, but sometimes it throw timeout ex or hang my Windows (Vista), only reset helps :) Why this can 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:


This is just a wild guess, but have you tried to move the Pool creation into the if block? I suspect that otherwise it might spawn an unlimited number of new processes, causing the freeze.



来源:https://stackoverflow.com/questions/3674746/python2-5-multiprocessing-pool

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!