fiber(cooperative multi-threading)

Arnaud Delobelle arnodel at googlemail.com
Sat Dec 22 09:55:36 EST 2007


On Dec 22, 2:37 pm, Duncan Booth <duncan.bo... at invalid.invalid> wrote:
> Arnaud Delobelle <arno... at googlemail.com> wrote:
> > I am not really familiar with ruby but these fibers seem to be some
> > sort of coroutines.  Since python 2.5, generators can be sent values,
> > this can be used to implement what you want.  I have had a got at it
> > for fun and this is what I came up with: note that there is no need
> > for a specific class, or for threads.  I have tested this only on your
> > example, but it gives the same result as your code :)
>
> I think it was Microsoft who invented the term 'fiber' as a synonym for
> coroutine. Seehttp://msdn2.microsoft.com/en-us/library/ms682661.aspx

OK

> Unfortunately generators only save a single level of stack-frame, so they
> are not really a replacement for fibers/coroutines. The OP should perhaps
> look at Stackless Python or Greenlets. Seehttp://codespeak.net/py/dist/greenlet.html

Still what I am proposing offers a level of cooperative multi-
threading which may be enough for the OP.  In fact it is not clear to
me at the moment what can be done (sensibly :) with the OP's Fiber
class that cannot be achieved with the run() function I suggested.
This makes me think that there is something important that I am
failing to take into consideration; I would be grateful if it was
pointed out to me.

--
Arnaud




More information about the Python-list mailing list