fiber(cooperative multi-threading)

Duncan Booth duncan.booth at invalid.invalid
Mon Dec 24 06:24:02 EST 2007


Michael Sparks <ms at cerenity.org> wrote:

> To be clear - I REALLY didn't like the fact that generators were
> single layer when I first saw them - it seemed a huge limitation.
> (Indeed as huge a limitation as only having single level function
> calls, or only single layer of nesting for namespaces, etc)... I even
> asked a question [3] on that point before choosing python to write
> Kamaelia in... The fact that it's been a benefit rather than a problem
> rather surprised me. 

Ok, I've now spent a little while browsing Kamaelia and it does look 
impressive. I'll need a bit longer to look at it in more detail.

Let me try again:

There are problems for which generators saving only a single stack frame 
are an excellent solution. e.g. a situation like yours where if I 
understand it you may have thousands of separate generators all in 
existence simultaneously.

There are also problems where full blown coroutines are appropriate. The 
example I quoted earlier of turning a parser from one which generates a lot 
of callbacks to one which 'yields' tokens is the usual example given.

There are also some situations where threads are appropriate: just not 
nearly as many situations as some people think.

I'm happy with generators as they are: they're a great solution to a 
problem that most of us didn't realise we had until the solution came 
along. That doesn't mean that I wouldn't also like to have a separate 
coroutine library, but I would use it to replace situations that might 
otherwise have to use threads, not to replace generators.

> Incidentally, you may note that you helped me back then (which I'm
> thankful for :-), so you can kinda view this as me reporting back
> "actually, it's turned out to be helpful rather than a pain" :-) Took
> a while to figure that out though ;)
> 
> Your mileage may vary :)
> 
> Incidentally, it was probably your response (message 7) in that thread
> that was responsible for me deciding to see where things could go by
> trying python :-)
> 
Thanks you. I really do intend *most* of my posts to be helpful.



More information about the Python-list mailing list