[Stackless] Select() on channels?
arnarbi at gmail.com
Sat Sep 15 02:56:16 CEST 2007
On 9/14/07, Richard Tew <richard.m.tew at gmail.com> wrote:
> def alt_select(*channels):
> resultChannel = stackless.channel()
> # See if anything is already waiting, and if so return it.
> for c in channels:
> if c.balance > 0:
> return c.receive()
If the alt_select is inside a loop and there's always something
available on some channel, this will cause starvation of the channels
that come after that one in the list. The CSP model calls for
non-determinism here but with a condition that when multiple channels
have available data, you should give them all an equal probability of
being selected so in the long run they all get served.
> tasklets = 
> for inputChannel in channels:
> firstTasklet, firstChannel, result = resultChannel.receive()
> for tasklet in tasklets:
> if tasklet is not firstTasklet:
> return firstChannel, result
More information about the Stackless