[Python-Dev] PEP 334 - Simple Coroutines via SuspendIteration (original) (raw)
Clark C. Evans cce at clarkevans.com
Wed Sep 8 21:58:53 CEST 2004
- Previous message: [Python-Dev] PEP 334 - Simple Coroutines via SuspendIteration
- Next message: [Python-Dev] PEP 334 - Simple Coroutines via SuspendIteration
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Wed, Sep 08, 2004 at 09:33:10PM +0200, Samuele Pedroni wrote: | Clark C. Evans wrote: | >I was assuming that only calls within the generator to next(), implicit | >or otherwise, would be suspension points. || I missed that.
nod I will fix the PEP.
| >This covers all of my use cases anyway. In the other situations, if | >they are even useful, don't do that. Convert the SuspendIteration to a | >RuntimeError, or resume at the previous suspension point? | > | >The idea of the PEP was that a nested-generator context provides this | >limited set of suspension points to make an implementation possible. || then the PEP needs clarification because I had the impression that || def g(src): | data = src.read() | yield data | data = src.read() | yield data
The data producers would all be iterators, ones that that could possibly raise SuspendIteration() from within their next() method.
| the read itself could throw a SuspendIteration
If read() did raise a SuspendIteration() exception, then it would make sense to terminate the generator, perhaps with a RuntimeError. I just hadn't considered this case. If someone has a clever solution that makes this case work, great, but its not something that I was contemplating.
| and upon the sucessive | next the src.read() itself would be retried. | But if it's only nexts than | can be suspension points then the generator would be not resumable in | this case.
Right.
I was musing (but it's not in the PEP) that, iter() would sprout an option that let the producer know if it can suspend. If a generator that was itself called with this suspend flag asked for a child generator, then the suspend flag would be carried. But this is a separate issue.
Thanks for thinking about this PEP.
Clark
-- Clark C. Evans Prometheus Research, LLC. http://www.prometheusresearch.com/ o office: +1.203.777.2550 ~/ , mobile: +1.203.444.0557 // (( Prometheus Research: Transforming Data Into Knowledge \ , / - Research Exchange Database /\ - Survey & Assessment Technologies ` \ - Software Tools for Researchers ~ *
- Previous message: [Python-Dev] PEP 334 - Simple Coroutines via SuspendIteration
- Next message: [Python-Dev] PEP 334 - Simple Coroutines via SuspendIteration
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]