[Distutils] in search of graceful co-routines

Chris Withers chris at simplistix.co.uk
Wed May 18 07:07:35 CEST 2011


The main python list :-)

Chris

On 17/05/2011 23:41, phil jones wrote:
> Yes, but it's a fascinating question. Where can I follow the answers?
>
> phil
>
> On Tue, May 17, 2011 at 6:04 PM, Chris Withers<chris at simplistix.co.uk>  wrote:
>> Apologies, wrong list...
>>
>> Chris
>>
>> On 17/05/2011 17:53, Chris Withers wrote:
>>>
>>> Hi All,
>>>
>>> I'm looking for a graceful pattern for the situation where I have a
>>> provider of a sequence, the consumer of a sequence and code to moderate
>>> the two, and where I'd like to consumer to be able to signal to the
>>> provider that it hasn't succeeded in processing one element in the queue.
>>>
>>> So, I'd want the controlling code to look a lot like:
>>>
>>> for item in provider:
>>> try:
>>> consumer.handleItem(self)
>>> except:
>>> provider.failed(item)
>>>
>>> Now, since the sequence is long, and comes from a file, I wanted the
>>> provider to be an iterator, so it occurred to me I could try and use the
>>> new 2-way generator communication to solve the "communicate back with
>>> the provider", with something like:
>>>
>>> for item in provider:
>>> try:
>>> consumer.handleItem(self)
>>> except:
>>> provider.send('fail')
>>> else:
>>> provider.send('succeed')
>>>
>>> ..but of course, this won't work, as 'send' causes the provider
>>> iteration to continue and then returns a value itself. That feels weird
>>> and wrong to me, but I guess my use case might not be what was intended
>>> for the send method.
>>>
>>> Anyway, I wonder how other people would write this?
>>> (I'm particularly interested in a sane way to use the two way
>>> communication that PEP 342 introduced)
>>>
>>> cheers,
>>>
>>> Chris
>>>
>>
>> --
>> Simplistix - Content Management, Batch Processing&  Python Consulting
>>            - http://www.simplistix.co.uk
>> _______________________________________________
>> Distutils-SIG maillist  -  Distutils-SIG at python.org
>> http://mail.python.org/mailman/listinfo/distutils-sig
>>
>
> ______________________________________________________________________
> This email has been scanned by the MessageLabs Email Security System.
> For more information please visit http://www.messagelabs.com/email
> ______________________________________________________________________

-- 
Simplistix - Content Management, Batch Processing & Python Consulting
            - http://www.simplistix.co.uk


More information about the Distutils-SIG mailing list