pythonmultiprocessing

Multithreading, can't run Process command


I am trying to the following code:

#!/usr/bin/python
import multiprocessing

def f(name): 
print 'hello', name

if __name__ == '__main__':
    p = multiprocessing.Process(target=f, args=('bob',))
    p.start()
    p.join()

The output I get is :

Traceback (most recent call last):
  File "a.py", line 9, in <module>
    p = multiprocessing.Process(target=f, args=('bob',))
AttributeError: 'module' object has no attribute 'Process'

Solution

  • You are trying to import multiprocessing from your local directory and not from the python library. The python interpreter first tries to import the module from the present directory. As you have got a file with the name multiprocessing.pyc in your directory, the interpreter is trying to import that. Hence you have got the error. Thus deleting multiprocessing.pyc will help resolve your problem.