Tim Evans wrote:
It depends on what you need to do, and on what you are comfortable using. Threads are good if what you are doing is going to take a long time and can't be divided up into small chunks that can be executed in an idle callback. Even if something can be done in multiple idle handlers I find that it is *sometimes* easier to use a separate thread.

The primary disadvantage of threads is that synchronisation problems and race conditions can get very complex if you aren't careful. Use Python's 'Queue' module for everything; if your algorithm requires something more complicated than Queue then change your algorithm ;-)

Thanx for the tip with Queue (I have missed this module till now), but it has a couple of drawbacks - many of the operations are not reliable (as the docs also say) as the locking is done inside the Queue methods. For what I want to do, I prefer to do the locking outside the queue class. I will probably replace my current stack with a fifo however.


I'll probably stick with threads as I think it is a bit cleaner this way ...

The final result should be a simple 'icon view' class. Scrolling should be very responsive, but the icons will appear only if the scrolling stops long enough.

The algorithm I use is simple:
- on scroll or resize, I clear the window and the queue and put in the queue the icons that need to be displayed;
- the thread takes the icon index fromthe queue and displays them if it has enough time;
- if another scroll message arrives before the icon thread had finished displaying the icons, the queue is cleared and icons not displayed are ignored.


I was going to use a tread for displaying the labels too, but I'll probably do the label stuff in the event handler, not in a separate thread.

Ionutz

_______________________________________________
pygtk mailing list   [EMAIL PROTECTED]
http://www.daa.com.au/mailman/listinfo/pygtk
Read the PyGTK FAQ: http://www.async.com.br/faq/pygtk/

Reply via email to