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