Send one-way message to all threads in Python

纵饮孤独 提交于 2019-12-18 07:06:39

问题


I need to send information to every thread that's running in my program, and every thread has to process that information.

I can't do it using a regular queue, because that way once one thread removes the data from the queue all the other threads won't be able to see it anymore.

What's the best way of achieving this?


回答1:


One way is to have a queue for each thread, and the function that broadcasts the information is responsible for inserting the message into the queue of every thread.

This is similar to the way message queues work in Windows, for example. Each thread that does GUI operations has an associated message queue, independent from that of any other thread.



来源:https://stackoverflow.com/questions/4531564/send-one-way-message-to-all-threads-in-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!