is there enough information?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Feb 27 02:46:56 EST 2008


En Wed, 27 Feb 2008 00:50:19 -0200, <castironpi at gmail.com> escribió:

> On Feb 26, 8:31 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
> wrote:
>> En Tue, 26 Feb 2008 15:49:00 -0200, <castiro... at gmail.com> escribió:
>>
>> > I'm not quite sure a semaphore is exactly the synchronization object
>> > I'm looking for, but I'm a little new to concurrency myself.
>>
>> The easiest way to implement a producer-consumer model in Python, is  
>> using  
>> a Queue.Queue object. It already implements the necesary  
>> synchronization  
>> mechanisms. The producer(s) put items in the Queue; the consumer(s) get  
>> items from it.
>
> Doesn't Queue.Queue operate by side effect?

What side effect? Producer thread(s) put items in the queue; consumer  
thread(s) get items from it; the queue just ensures the proper  
syncronization between them.

It's like a McDonalds: three guys (the producers) are taking orders from  
the customers, and place those orders in a queue; in the kitchen, two guys  
(the consumers) check the queue and prepare the requested sandwichs (it  
doesn't matter which one gets which order). The finished sandwichs are put  
onto another queue (the kitchen guys are acting as producers now) and  
another guy -he may or may not be one of the first three; he's acting as a  
consumer- takes the sandwich, puts it on a tray with other stuff and  
delivers it to the customer.

-- 
Gabriel Genellina




More information about the Python-list mailing list