How to convert 'from Queue import Queue, Empty' from Python 2 to Python 3? [duplicate]

瘦欲@ 提交于 2020-01-02 08:21:25

问题


I'm converting a source code written in Python 2 to Python 3 and I stumbled into this:

from Queue import Queue, Empty

I changed it to:

from multiprocessing import Queue, Empty

But this gives me an exception:

ImportError: cannot import name 'Empty'

How do I fix this?


回答1:


multiprocessing.Queue is used for processes, don't let the capitalization confuse you. Queue, which was renamed to queue in Python 3, is for threads.

Both Empty and Queue are located in the queue module, so grab them from there.



来源:https://stackoverflow.com/questions/41150948/how-to-convert-from-queue-import-queue-empty-from-python-2-to-python-3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!