Generators versus Coroutines
Bryan Olson
bryanjugglercryptographer at yahoo.com
Wed Aug 18 19:17:04 EDT 2004
Dominic wrote:
[Bryan had written:]
> > I've seen servers that rock written with explicit event handling,
> > threads, processes, and occasionally co-routines. Where are the
> > great generator-based servers?
> Well, the Erlang (language + telecom platform) uses light-weight
> threads which could e.g. be implemented with coroutines in Python.
Well, the issue here is whether they could be implemented
reasonably in Python as it currently is, with generators
but not co-routines.
> Event handling is fine but you could also explicitly code
> your behaviour as state machines ;-)
Hmm, I wasn't distinguishing the two.
> The drawback of event
> handling is that you have to separate state and control flow
> and resuming is error prone whereas generators and coroutines
> are easier and feel more natural.
Right. Every time you do anything that might block, you have to
save your state and return all the way out to the event handler.
I think Python generators are about as awkward; you have to
explicitly yield through every stacked call. Preserving the
local variables seems to be the only advantage.
--
--Bryan
More information about the Python-list
mailing list