python2.5多处理池 [英] python2.5 multiprocessing Pool

查看:94
本文介绍了python2.5多处理池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拥有python2.5和多处理器功能(从 http://code.google获得. com/p/python-multiprocessing/)

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

这个简单的代码(从文档中获取)有时会很奇怪,有时还可以,但有时会抛出超时或挂起我的Windows(Vista),仅重置帮助:)为什么会发生这种情况?

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

推荐答案

这只是一个疯狂的猜测,但是您是否尝试将Pool创建的内容移到if块中?我怀疑,否则它可能会产生无限数量的新进程,从而导致冻结.

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.

这篇关于python2.5多处理池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆