Re: in search of graceful co-routines

2011-05-17 Thread Chris Withers
On 18/05/2011 03:10, Terry Reedy wrote: By default, Python iterators operate in pull mode -- consumers request a new item when they want one. I believe .send was mostly intended to reverse that, to operate in push mode where producers .send() a item to a consumer when they are ready to. That is c

Re: in search of graceful co-routines

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 11:27 PM, Chris Withers wrote: > Yes, but it's this kind of birds nest I'm trying to avoid... I was actually kind of hoping you might see it that way. That's about as simple as you're going to get using a generator for this, though. I'll second Terry's suggestion on this:

Re: in search of graceful co-routines

2011-05-17 Thread Chris Withers
On 17/05/2011 18:26, Ian Kelly wrote: You can use send the way you're wanting to. It will look something like this: def provider(): result = None while True: if result is None: if has_more_items(): next_item = get_next_item() else: break elif resu

Re: in search of graceful co-routines

2011-05-17 Thread Chris Angelico
On Wed, May 18, 2011 at 3:04 AM, 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 >

Re: in search of graceful co-routines

2011-05-17 Thread Terry Reedy
On 5/17/2011 1:04 PM, 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

Re: in search of graceful co-routines

2011-05-17 Thread Carl Banks
On Tuesday, May 17, 2011 10:04:25 AM UTC-7, Chris Withers wrote: > 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 provide

Re: in search of graceful co-routines

2011-05-17 Thread Ian Kelly
On Tue, May 17, 2011 at 11:04 AM, Chris Withers wrote: > 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 som