Queue.Queue is just a queue in memory that knows how to handle multiple threads using it at the same time. It only works if both the manufacturer and the consumer are in the same process.
After you use them in separate system processes, what is the multiprocessing library, everything is a little more complicated, because the processes no longer use the same memory. You need some kind of interprocess communication method that allows the two processes to communicate with each other. It could be shared memory, a pipe or socket, or perhaps something else. This is what multiprocessing.Queue does. It uses channels to allow two processes to interact. It just implements the same API as Queue.Queue , because most Python programmers are already familiar with it.
Also note that as you use the queue, you have a race condition in your program. Think about what happens if the write process writes to the queue right after q.empty() called in the read process. Usually you add some special element to the queue (for example, None ), which means that the consumer can stop.
Lukáš Lalinský
source share