Generators versus Coroutines

Lenard Lindstrom len-1 at telus.net
Tue Aug 17 18:08:48 CEST 2004


Nick Patavalis <npat at efault.net> writes:

> On 2004-08-16, Lenard Lindstrom <len-1 at telus.net> wrote:
> >
> > As for doing it in Python, coroutines can be implemented using 
> > threads.
> >
> 
> But threads cost! And how much they cost depends on the operating
> system. Coroutines cost close to nothing, and are O/S independent. The
> only reason to use O/S threads is if you need preemption, and if you
> want to cater for parallel execution.
> 
I do not consider using threads to implement coroutines a practical
solution. It was alluded to in a posting by Tim Peters giving his take
on generators, coroutines and continuations. The case he mentioned was
more than likely a demonstration or example than an actual production
module.

Lenard Lindstrom
<len-l at telus.net>



More information about the Python-list mailing list