问题
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