[Stackless] Select() on channels?
tismer at stackless.com
Fri Sep 14 19:41:53 CEST 2007
> Is there any way to wait on a set of channels
> for the first one to become available?
> I have an application where it would be
> tremendously helpful to be able to receive()
> on a set of channels at once.
> If there's not already a mechanism, I would
> propose something like:
> stackless.channel.multireceive(ch1, ch2, ...)
> which returns a (channel, value) pair providing
> the channel that had data and the value from
> that channel. (Returning a pair eliminates the
> double-dip problem that the Unix select() system
> call suffers from.)
This is a thing definitely needed, and it was discussed
a little from time to time, last time on IRC.
This is the ALT statement from Limbo, there is something similar
in CSP, Occam and others.
The other side of the coin is how to generalize waiting for data
on multiple I/O channels simultaneously to a very high scale,
which could make Stackless much more considerable for some
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.
cheers - chris
Christian Tismer :^) <mailto:tismer at stackless.com>
tismerysoft GmbH : Have a break! Take a ride on Python's
Johannes-Niemeyer-Weg 9A : *Starship* http://starship.python.net/
14109 Berlin : PGP key -> http://wwwkeys.pgp.net/
work +49 30 802 86 56 mobile +49 173 24 18 776 fax +49 30 80 90 57 05
PGP 0x57F3BF04 9064 F4E1 D754 C2FF 1619 305B C09C 5A3B 57F3 BF04
whom do you want to sponsor today? http://www.stackless.com/
More information about the Stackless