[Python-Dev] Coroutines (PEP 342)

Martin Blais blais at furius.ca
Fri Nov 18 00:26:22 CET 2005

On 11/14/05, Bruce Eckel <BruceEckel-Python3234 at mailblocks.com> wrote:
> I just finished reading PEP 342, and it appears to follow Hoare's
> Communicating Sequential Processes (CSP) where a process is a
> coroutine, and the communicaion is via yield and send(). It seems that
> if you follow that form (and you don't seem forced to, pythonically),
> then synchronization is not an issue.
> What is not clear to me, and is not discussed in the PEP, is whether
> coroutines can be distributed among multiple processors. If that is or
> isn't possible I think it should be explained in the PEP, and I'd be
> interested in know about it here (and ideally why it would or wouldn't
> work).

It seems to me that the concept of coroutines and PEP342 has very
little to do with concurrency itself, apart from the fact that the
generators form very convenient units of parallelization if you're
willing to do some scheduling of them yourself, and only *potentially*
with concurrency, i.e. only if you wrote a scheduler that supports
running generator iterations concurrently on two processors. 
Otherwise there is no concurrency abstraction, unlike threads: it's
cooperative and you clearly can see in the code the points where
"switching" occurs (next(... ), yield ...).

Please beat me with a stick if this is lunatic...

More information about the Python-Dev mailing list