[Stackless] Select() on channels?
Tim Kientzle
tim at metaweb.com
Fri Sep 14 20:07:44 CEST 2007
Christian Tismer wrote:
>
>> Is there any way to wait on a set of channels
>> for the first one to become available?
>
> No. *)
> The other side of the coin is how to generalize waiting for data
> on multiple I/O channels simultaneously to a very high scale ...
> http://www.kegel.com/c10k.html
Yes, Dan Kegel's paper has certainly inspired a lot of
my own thinking along these lines. (Although supporting c10k
in any interpreted language still seems quite ambitious.)
> An inefficient but probably working solution is this silly idea:
>
> - For each of the n channels to be waited on, create a tasklet
> that blocks reading on this channel.
>
> - it runs code like this after the receive:
> - kill the other extra tasklets
> - send the result on the multi-channel
>
> Instead of killing, also a dummy value could be sent, that tells
> the other tasklets to do no action.
In my case, I can probably work around it with a simple
"aggregator" channel. There's a tasklet for each
channel that does the equivalent of:
def feed_tasklet(ch, aggregator):
while True:
v = ch.receive()
aggregator.send((ch, v))
Then the main tasklet can just receive from the
aggregator channel to get a list of events in whatever
order they occur.
Tim Kientzle
More information about the Stackless
mailing list