python2.5多处理池

标签 python multiprocessing

我有 python2.5 和多处理器(来自 http://code.google.com/p/python-multiprocessing/ )

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

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 block 中?我怀疑否则它可能会产生无限数量的新进程,从而导致卡住。

关于python2.5多处理池,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3674746/

相关文章:

python - 使用我自己的数据的 Tensorflow 错误

Python 多处理 - 将字典列表传递到池

python-3.x - python apply_async不调用方法

python - 使用 cython 进行慢速多处理

python - 如何增加matplotlib “table” plot的高度

python - 在 Python 中使用列表方法加速 for 循环

python - 确定 ThreadPool 何时完成处理队列

python - TQDM 和多处理 - python

python - GeoJSON 数据不包含有意义的数据 GeoDjango

python - 如何解析只有数字的 JSON