相关疑难解决方法(0)

给出AttributeError的多处理示例

我试图在我的代码中实现多处理,所以,我想我会开始学习一些例子.我使用了本文档中的第一个示例.

from multiprocessing import Pool
def f(x):
    return x*x

if __name__ == '__main__':
    with Pool(5) as p:
        print(p.map(f, [1, 2, 3]))
Run Code Online (Sandbox Code Playgroud)

当我运行上面的代码时,我得到了一个AttributeError: can't get attribute 'f' on <module '__main__' (built-in)>.我不知道为什么我会收到这个错误.如果有帮助,我也使用Python 3.5.

python multithreading

22
推荐指数
3
解决办法
1万
查看次数

标签 统计

multithreading ×1

python ×1