I am trying some simple programs which involve multiprocessing features in Python.
The code is given below:
from multiprocessing import Process, Queue
def print_square(i):
print i*i
if __name__ == '__main__':
output = Queue()
processes = [Process(target=print_square,args=(i,)) for i in range(5)]
for p in processes:
p.start()
for p in processes:
p.join()
However, this gives an error message AttributeError: 'module' object has no attribute 'heappush'. The complete output upon executing the script is given below:
Traceback (most recent call last):
File "parallel_3.py", line 15, in
output = Queue()
File "C:\Users\abc\AppData\Local\Continuum\Anaconda2\lib\multi
processing\__init__.py", line 217, in Queue
from multiprocessing.queues import Queue
File "C:\Users\abc\AppData\Local\Continuum\Anaconda2\lib\multi
processing\queues.py", line 45, in
from Queue import Empty, Full
File "C:\Users\abc\AppData\Local\Continuum\Anaconda2\lib\Queue
.py", line 212, in
class PriorityQueue(Queue):
File "C:\Users\abc\AppData\Local\Continuum\Anaconda2\lib\Queue
.py", line 224, in PriorityQueue
def _put(self, item, heappush=heapq.heappush):
AttributeError: 'module' object has no attribute 'heappush'
The code compiles fine if the output=Queue() statement is commented. What could be possibly causing this error ?
heapq.pysomewhere that's hiding the Python one?