A little threading problem

Alban Hertroys alban at magproductions.nl
Thu Dec 2 09:18:21 EST 2004


Jeremy Jones wrote:
> * the get method on a queue object has a "block" flag.  You can 
> effectively poll your queues something like this:
> 
> #untested code
> #a_done, b_done and c_done are just checks to see if that particular 
> document is done
> while not (a_done and b_done and c_done):
>    got_a, got_b, got_c = False, False, False
>    item_a, item_b, item_c = None, None, None
>    while (not a_done) and (not got_a):
>       try:
>          item_a = queue_a.get(0) #the 0 says don't block and raise an 
> Empty exception if there's nothing there

Actually, it is just fine to let get() block, as long as I put(None) on 
the queue when I reach document_end and test for it (removing it from 
the "list of queues to read" when get() returns 'None').

I rewrote my test script (the one I sent to the NG) to use Queues this 
way, and it works well. It's also a lot easier to read/follow. Currently 
I'm implementing it in my application.
I'm glad I don't get paid by the number of lines I write, there are 
going to be less lines at the end of today ;)

Thanks a lot for the pointers.



More information about the Python-list mailing list