[Stackless] Coroutines
Jimmie Houchin
jhouchin at cableone.net
Thu May 27 17:57:48 CEST 2004
Thanks,
I'll give that a try.
Jimmie
Christian Tismer wrote:
> Jimmie Houchin wrote:
>
>> Hello,
>>
>> I am trying to learn coroutines.
>>
>> Is there any tutorial or documentation on how to use coroutines with
>> Stackless.
>
>
> There will be more direct support soon, but here is
> the simple way:
> take two tasklets, give them a channel, and let them talk.
>
> def coro1(ch):
> while somecondition:
> # do some stuff
> # talk to the other one
> ch.send(result)
> # ...
>
> def coro2(ch):
> while someothercondition:
> # do some other stuff
> # get info of other coroutine
> info = ch.receive()
> # ...
>
> #Ok, now run that stuff:
>
> from stackless import *
>
> ch = channel()
> t1 = tasklet(coro1)(ch)
> t2 = tasklet(coro2)(ch)
>
> # run waits until there is no tasklet to run anymore
>
> run()
>
_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless
More information about the Stackless
mailing list