Multiprocessing program has AttributeError attribute in Anaconda notebook

I am running a simple Hello World program on a 64-bit version of Windows 7 with the following features:

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

Program:

 from multiprocessing import Process, freeze_support def f(): print ('hello world!') if __name__ == '__main__': #freeze_support() Process(target=f).start() 

gives the following error:

 [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) 
+6
source share
1 answer

This is due to the fact that multiprocessing does not work in the interactive interpreter. The main reason is that there is no fork () function in windows. This is explained on the web page itself.

"The functionality in this package requires the child module to import the main module. This is described in the Programming Guide, but it is worth pointing out here. This means that some examples, such as multiprocessing.Pool examples, will not work in the interactive interpreter."

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

The same problem will occur if you use the pool function in multiprocessing. It is decided in this post. Therefore, you can use this method to implement the idea of โ€‹โ€‹parallel processing.

Python multiprocessing apply_async never returns result in Windows 7

Hope this is helpful information for you.

+4
source

All Articles