【问题标题】:How to convert 'from Queue import Queue, Empty' from Python 2 to Python 3? [duplicate]如何将“从队列导入队列,空”从 Python 2 转换为 Python 3? [复制]
【发布时间】:2017-04-30 06:37:23
【问题描述】:

我正在将用 Python 2 编写的源代码转换为 Python 3,我偶然发现了这个:

from Queue import Queue, Empty

我改成:

from multiprocessing import Queue, Empty

但这给了我一个例外:

ImportError: cannot import name 'Empty'

我该如何解决这个问题?

【问题讨论】:

  • Queue 在 python 3 中是 queue
  • from queue import Queue, Empty

标签: python python-2.7 python-3.x queue multiprocessing


【解决方案1】:

multiprocessing.Queue 用于进程,不要让大写混淆你。 Queue,在 Python 3 中重命名为 queue,用于线程。

EmptyQueue 都位于 queue 模块中,因此请从那里获取它们。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-09
    • 1970-01-01
    • 1970-01-01
    • 2020-10-12
    • 2018-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多