[PyKDE] Multithreaded GUI programming

Jonathan Gardner jgardn at alumni.washington.edu
Sat Dec 7 00:30:00 GMT 2002


On Friday 06 December 2002 03:50 am, Michael Lauer wrote:
>
> Our setup is a typical multithreaded one: We have a number of worker
> threads and one GUI thread,
> both communicating via a Queue. The problem is: How not to waste CPU
> resources by using a timer
> to poll the communication Queue from within the GUI thread.
>
> Some more information: Since we're targetting a PDA with Qt/Embedded,
> we're using PyQt.
> The PDA runs a non-threaded Qt/Embedded 2.3.4 and will for quite a long
> time. Qt/E 2.3.4
> is _not_ thread-safe, so all calls to Qt must be done from same thread.
> This also means,
> it's unfortunately not possible to call QApplication.postEvent() from a
> worker thread
> to make the GUI thread to check for a new message in the Queue.
>

I'd say you are stuck. I would imagine that the timer is pretty efficient, and 
if it isn't, well it should be. Since you don't have the option of using 
select(), it's the only way to go. I'd be pretty interested myself if there 
is a way around this.

The other thought is to use a timer that doesn't tick every once in a while. 
Basically, you set it to tick after a set time when you launch the thread, or 
start the task in the thread. Then when it ticks, you can check to see if it 
is finished, show an update to the screen and do whatever you would normally 
do. Set it to tick again if the task isn't finished, and call the same 
routine.

The only benefit of this is that when your app isn't doing anything, it won't 
be taking resources either. However, it will be using a little more when 
something is happening in the background.

-- 
Jonathan Gardner
jgardn at alumni.washington.edu




More information about the PyQt mailing list