[英]Python error : AttributeError: 'module' object has no attribute 'heappush'
I am trying some simple programs which involve multiprocessing features in Python. 我正在尝试一些简单的程序,这些程序涉及Python中的多处理功能。
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'.
但是,这会给出一条错误消息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. 如果对output = Queue()语句进行注释,则代码可以正常编译。 What could be possibly causing this error ? 是什么可能导致此错误?
Your filename should be the package name. 您的文件名应为程序包名称。 Change to another filename such as heap
and it will work. 更改为另一个文件名,例如heap
,它将起作用。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.