Reputation: 3782
My main question: can you have several processes write to one queue in a loop and use that queue to update a 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. I would like to have a GUI which displays the progress of several different processes at the same time. 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.
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?
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.
Upvotes: 1
Views: 482
Reputation: 1244
Most GUI systems are event driven and expect all event handling to come from a single thread. This is true of the Windows event system, Android events, Swing, and probably many others. 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. 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.
Upvotes: 1