What are the fundamental differences between queues and pipes in Python’s multiprocessing package?
In what scenarios should one choose one over the other? When is it advantageous to use Pipe()? When is it advantageous to use Queue()?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Major Edit of this answer (CY2024): concurrency
As of modern python versions if you don’t need your producers and consumers to communicate, that’s the only real use-case for python
multiprocessing.If you only need python concurrency, use
concurrent.futures.This example uses
concurrent.futuresto make four calls todo_something_slow(), which has a one-second delay. If your machine has at least four cores, running this four-second-aggregate series of function calls only takes one-second.By default,
concurrent.futuresspawns workers corresponding to the number of CPU cores you have.With at least four CPU cores, you’ll see this printed after roughly one-second…
Original Answer
At this point, the only major use-case for
multiprocessingis to facilitate your producers and consumers talking to each other during execution. Most people don’t need that. However, if you want communication via queue / pipes, you can find my original answer to the OP’s question below (which profiles how fast they are).The existing comments on this answer refer to the aforementioned answer below