[Stackless] Select() on channels?

Arnar Birgisson arnarbi at gmail.com
Mon Sep 17 19:35:39 CEST 2007


On 9/17/07, Tim Kientzle <tim at metaweb.com> wrote:
> Arnar Birgisson wrote:
> > On 9/15/07, Santiago Gala <sgala at apache.org> wrote:
> >
> >> For a truly stateless implementation alt_select should probably use
> >> random "shuffling" of the list of channels before iterating.
> >
> > Yes, forgetting about efficiency for a while, something like this:
> >
> > import random
> > ready_channels = [c for c in channels if c.balance > 0]
> > if len(ready_channels):
> >     c = random.choice(ready_channels)
> >     return c, c.receive()
>
> Why not just move each ready channel to the
> end of the list?

Because you have no guarantee that the list hasn't changed
significantly between invocations. Channels may have been added,
removed and/or completely shuffled around.

Arnar




More information about the Stackless mailing list