[Tutor] python queue
Jeff Peery
jeffpeery at yahoo.com
Thu Sep 17 02:04:45 CEST 2009
Hello,
Does anyone know if there is there a way to look at a queue's contents? Or prevent duplicate messages from being put into a queue? The docs don't show anything useful. The reason is that I'm collecting and drawing data. one thread collects, and one thread draws. each time one sample is collected by the collector thread, a "draw message" is put into the queue to notify the drawing thread. the dataset is shared between the threads and is continuously growing as data is appended. The queue is used to notify the drawing thread that it should draw. I use threading.Lock() to prevent any "sharing issues".
The problem is that if the data collector thread is putting messages into the queue faster than the drawing thread is getting them, then the drawing thread is forced to redraw more times than it needs to and appears slow. However since the dataset is shared the drawing thread only needs to draw once to be updated for all the new samples. For example if 10 samples have been appended by the data collector thread while the drawing thread drew once, then there are now 10 messages for the drawing thread to get. yet it only needs to draw once to reflect the 10 samples. so there are 9 redraws that are a waste of energy.
I was hoping there was some feature in the queue class the would prevent or discard a duplicate message. This way my drawing thread won't draw more than it needs to.
thanks!
Jeff
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20090916/85c0cda7/attachment.htm>
More information about the Tutor
mailing list