Reputation: 11
I am new in Python, and I am trying to learn how to run several functions in parallel. Using the Python documentation I started following some simple examples, but even the simplest one leads me to an error. The piece of code I am trying to use is this:
from multiprocessing import Pool
def f(x):
return x*x
if __name__ == '__main__':
p = Pool(5)
print(p.map(f, [1, 2, 3]))`
However, I get this error (the code is called chat):
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "c:\python27\lib\multiprocessing\forking.py", line 380, in main
prepare(preparation_data)
File "c:\python27\lib\multiprocessing\forking.py", line 503, in prepare
file, path_name, etc = imp.find_module(main_name, dirs)
ImportError: No module named chat
As i mentioned, I am new at this, so if someone could help me with this issue, i would very much appreciate it! I get similar error when instead of 'pool' I try with 'Process'.
Upvotes: 1
Views: 807
Reputation: 41
I'm aware this is quite a late reply, but just for future knowledge of anyone else who comes across an issue like this. Make sure you're using the correct case when calling the program name when using multiprocessing, if your file is called "My file" and you run:
c:\python27\python.exe "c:\projects\my file.py"
Under most circumstances it'll be fine, but when using the multiprocessing module it doesn't like it. So run:
c:\python27\python.exe "c:\projects\My File.py"
This issues wasted half a day of my time at one point...
Upvotes: 1