Coroutine API

Calvin Spealman ironfroggy at
Fri Aug 3 17:57:07 CEST 2007

I was talking to some other people, who all were working on different
schedulers and such for coroutines. We decided to work out a common
API to give coroutines, and common rules to passing data between them,
etc. I am wondering now if there is already work on this, or some
schedulers I'm not aware of that have any deployment and a good,
simple design.

We also setup a group to discuss this and iron out our details and
some common coroutines. python-coro at

We came up with this basic rule set:
1) A coroutine can be any iterable
2) A coroutine yielding None is suspending to allow others to run
3) A coroutine yielding something else is yielding another coroutine
and needs to stay suspended until that coroutine has a value to pass
to the send() method of the coroutine.
4) In the above case, if the yielded coroutine raises an exception, it
is passed to the waiting coroutine's throw() method.
5) A coroutine raising StopIteration(arg), where arg is its final
result, expects arg to be passed to the send() method of any coroutine
which is waiting for its completion.

The idea is that we don't rely on defining any new types or functions
and we keep it extremely simple. I'd like to consider it WSGI for

Read my blog! I depend on your acceptance of my opinion! I am interesting!

More information about the Python-list mailing list