问题描述
我需要向程序中运行的每个线程发送信息,并且每个线程都必须处理该信息.
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?
推荐答案
一种方法是为每个线程设置一个队列,广播信息的函数负责将消息插入到每个线程的队列.
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.
例如,这类似于消息队列在 Windows 中的工作方式.每个执行 GUI 操作的线程都有一个关联的消息队列,独立于任何其他线程.
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.
这篇关于向 Python 中的所有线程发送单向消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!


大气响应式网络建站服务公司织梦模板
高端大气html5设计公司网站源码
织梦dede网页模板下载素材销售下载站平台(带会员中心带筛选)
财税代理公司注册代理记账网站织梦模板(带手机端)
成人高考自考在职研究生教育机构网站源码(带手机端)
高端HTML5响应式企业集团通用类网站织梦模板(自适应手机端)