python - Windows 上没有名为 'Queue' 的模块

标签 python queue

我尝试在 Windows 上使用程序:

import random, time, Queue
from multiprocessing.managers import BaseManager

task_queue = Queue.Queue()
result_queue = Queue.Queue()

class QueueManager(BaseManager):
    pass

QueueManager.register('get_task_queue', callable=lambda: task_queue)
QueueManager.register('get_result_queue', callable=lambda: result_queue)

manager = QueueManager(address=('', 5000), authkey='abc')
manager.start()
task = manager.get_task_queue()
result = manager.get_result_queue()

for i in range(10):
    n = random.randint(0, 10000)
    print('Put task %d...' % n)
    task.put(n)
print('Try get results...')

for i in range(10):
   r = result.get(timeout=10)
   print('Result: %s' %r)
manager.shutdown()

我收到错误:

ImportError: No module named 'Queue'

但是我在 Ubuntu 中运行它,它可以工作。 我在 stackoverflow、pypi.python.org for windows 中搜索 Queue,并尝试 pip install Queue。最后还是失败了。那么如何在windows上使用Queue模块呢?

最佳答案

我猜你想使用多处理模块中的Queue,然后以这种方式导入 -

from multiprocessing import Queue

如果你想使用队列数据结构,那么你可以使用小写的queue

import queue

关于python - Windows 上没有名为 'Queue' 的模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41632356/

相关文章:

sql - 未显示检索队列算法

Java 具有优先级队列的可比较对象

php - Laravel Horizo​​n限制了总流程数量

python - Matplotlib 热图自动旋转图像

python 正在偷我的东西

python - PIL 无法识别 io.BytesIO 对象的图像文件

laravel - 覆盖 Laravel 队列监听器输出 [仅限 Laravel <=5.2]

python - Django 国际化---编译消息错误 :AttributeError: module 'locale' has no attribute 'normalize'

python - 如何更新模型

deployment - 在 ejb-jar.xml 中添加队列 JNDI 引用?在 EJB/MDB 中发送 JMS 消息