多处理程序在Anaconda笔记本中具有AttributeError [英] Multiprocessing program has AttributeError in Anaconda notebook

查看:86
本文介绍了多处理程序在Anaconda笔记本中具有AttributeError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Windows 7 64位操作系统上运行一个具有以下规范的简单"Hello World"程序:

I am running a simple "Hello World" program on Windows 7 64 bit with the following specifications:

Python 3.4.3 | Anaconda 2.3.0 (64-bit) | [MSC v.1600 64 bit (AMD64)] IPython 4.0.0

程序:

from multiprocessing import Process, freeze_support

def f():
    print ('hello world!')

if __name__ == '__main__':
    #freeze_support()
    Process(target=f).start()

出现以下错误:

[I 15:02:23.855 NotebookApp] Saving file at /uhc/FeatureContributionToK-meansClu
sterWithPC.ipynb
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "C:\Anaconda3\lib\multiprocessing\spawn.py", line 106, in spawn_main
    exitcode = _main(fd)
  File "C:\Anaconda3\lib\multiprocessing\spawn.py", line 116, in _main
    self = pickle.load(from_parent)
AttributeError: Can't get attribute 'f' on module '__main__' (built-in)  

推荐答案

这是因为在交互式解释器中多重处理效果不佳.主要原因是在Windows中没有适用的fork()函数.在他们的网页上对此进行了说明.

This is because of the fact that multiprocessing does not work well in the interactive interpreter. The main reason is that there is no fork() function applicable in windows. It is explained on their web page itself.

此软件包中的功能要求 main 模块必须可由子级导入.这在编程指南中已涉及到,但是在这里值得指出.这意味着一些示例,例如multiprocessing.Pool示例在交互式解释器中不起作用."

"Functionality within this package requires that the main module must be importable by the children. This is covered in Programming guidelines however it is worth pointing out here. This means that some examples, such as the multiprocessing.Pool examples will not work in the interactive interpreter."

https://docs.python.org/2/library/multiprocessing .html#windows

如果在多处理中使用池功能,也会出现同样的问题.在这篇文章中已解决.因此,您可以使用该方法来执行并行处理的想法.

This same problem will come if you are using pool function in multiprocessing. It is solved in this post . You can hence use that method for executing your idea of parallel processing.

Python多处理apply_async永不返回Windows 7上的结果

希望对您来说是有用的信息.

Hope it is a useful information to you.

这篇关于多处理程序在Anaconda笔记本中具有AttributeError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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