简体   繁体   中英

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?

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.Value or a multiprocessing.Array
  • if the purpose is to synchronise the next phase of some processing, you could use a multiprocessing Barrier or Event
  • 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 mosquitto broker.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM