简体   繁体   English

跨多个进程共享队列

[英]Shared queue across multiple processes

My main question: can you have several processes write to one queue in a loop and use that queue to update a GUI? 我的主要问题:您是否可以让多个进程在一个循环中写入一个队列,然后使用该队列更新GUI?

I have been looking at the posts regarding queues and multiple processes and I was wondering if anyone had any idea if it is possible or beneficial to use combinations of them. 我一直在查看有关队列和多个流程的帖子,我想知道是否有人知道使用它们的组合是否可能或有益。 My thought process is this: since all processors are made now with ~8 cores, most programs I make should have the ability to access this power if there is any part of the program that is at all computationally expensive. 我的思考过程是这样的:由于现在所有处理器都是使用〜8核制成的,因此如果程序中有任何部分在计算上非常昂贵,那么我制作的大多数程序都应该具有访问此功能的能力。 I would like to have a GUI which displays the progress of several different processes at the same time. 我希望有一个GUI同时显示几个不同进程的进度。 I would like each of these processes to use as much of the processors as possible, but they all have to write to the GUI at the same time, so from what I have read, it seems like a queue will work for this. 我希望每个进程都尽可能多地使用处理器,但是它们都必须同时写入GUI,因此从我阅读的内容来看,似乎可以使用队列。

Is the best way to approach this to have several processes communicate to a queue via a pipe, and have the queue update the GUI? 解决此问题的最佳方法是使多个进程通过管道与队列通信,并让队列更新GUI吗?

At the moment I am using pyQt signals and slots but I feel this is a bad solution for modern times since it only uses one CPU core. 目前,我正在使用pyQt信号和插槽,但是由于它仅使用一个CPU内核,因此我觉得对于现代而言,这是一个不好的解决方案。

Most GUI systems are event driven and expect all event handling to come from a single thread. 大多数GUI系统都是事件驱动的,并且期望所有事件处理都来自单个线程。 This is true of the Windows event system, Android events, Swing, and probably many others. Windows事件系统,Android事件,Swing以及其他许多事件都是如此。 In the case of GUIs, the practical benefit of making all the event management functions thread-safe is small, while the difficulty is quite large. 在GUI的情况下,使所有事件管理功能具有线程安全性的实际好处很小,而难度却很大。 Most large scale concurrent systems do combine event based and thread based approaches to concurrency, for instance modern browsers. 大多数大型并发系统确实将基于事件和基于线程的并发方法相结合,例如现代浏览器。 In your case, it's much simpler to just register an update event and have it posted to the event dispatching thread by your worker processes/threads. 在您的情况下,注册一个更新事件并由工作进程/线程将其发布到事件分派线程中要简单得多。 This way your GUI remains responsive to other windowing events as it is only being notified periodically. 这样,您的GUI只会对其他窗口事件做出响应,因为它只会定期得到通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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