[Python-Dev] Simple coroutines?

Greg Ewing greg at cosc.canterbury.ac.nz
Wed Aug 25 05:32:28 CEST 2004


"Clark C. Evans" <cce at clarkevans.com>:

> In fact, one could implement it using a SuspendIteration exception,
> in addition to a StopIteration.

I don't think this can be done quite right by raising an exception in
the normal way, because you don't want 'finally' clauses to be
triggered.

> You'd definately want to mix them.  For example, a 'cooperator'
> would be reading from a socket, it could do one of three things:
> 
>   yield the next line from the sender
>   raise StopIteration if the socket closed
>   raise SuspendIteration if the read() is blocked

Hmmm. It seems that generation and cooperation are really orthogonal
concepts -- you may want something that is both a generator *and* a
cooperator. My proposal doesn't allow for this. I will have to do some
more thinking...

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+


More information about the Python-Dev mailing list