'Broadcast message to multiple Multiprocessing processes
I have a Multiprocessing application with a bunch of processes, I want the control thread to broadcast a message to multiple processes. If I used a pipe pair for each there will be a ton of pipes.
Is there a way to send one message to multiple processes at the same time?
Solution 1:[1]
I think it depends what your actual purpose is in sending the message:
- if the purpose is to share a value/values amongst the processes, you can use a
multiprocessing.Valueor amultiprocessing.Array - if the purpose is to synchronise the next phase of some processing, you could use a
multiprocessingBarrierorEvent - if you really want to do "Pub/Sub" of lots of messages, you would probably want to use Pub/Sub from Redis or MQTT with
mosquittobroker.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mark Setchell |
