Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 878
Moaz Ashraf Avatar asked Nov 03 '25 15:11

Moaz Ashraf


1 Answers

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.

like image 126
Dimitris Fasarakis Hilliard Avatar answered Nov 06 '25 07:11

Dimitris Fasarakis Hilliard



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!