[Stackless] More CSP

Tom Locke tom at livelogix.com
Wed Jan 7 13:21:08 CET 2004

[NOTE: My email was dead for most of today - this is already out of
       Python implementation of alt *seems* to be working - will follow]

Hi All,

Having started to dig around, I'm coming to the conclusion that I may
start with an all-python solution that uses the existing channel support
and various scheduling hooks.

For example, par is very easy:

(For the uninitiated, A par construct runs a bunch of processes in
parallel, the par process itself terminates when all of the
sub-processes have terminated).

def par(*funcs):
    taskEnd = channel()
    def signalEnd(f):

    for f in funcs:

    count = len(funcs)
    while count > 0:
        count -= 1

#Example usage:

def counter(c, out):
    for x in range(1, c+1):

def accumulate(inp):
    acc = 0
    while 1:
        x = inp.receive()
        if x == 'end': break
        acc += x
    print acc

def test():
    c = channel()
        lambda: counter(6, c),
        lambda: accumulate(c)


I'm assuming it's ok to send on a channel from multiple tasklets?? In
occam this is a 'shared' channel, in JCSP an 'any-to-one' channel.

The use of a channel to signal tasklet-end is perhaps a bit heavy? Are
chan.send() and chan.receive() the only ways to make the *current*
tasklet block?

Implementing alt entirely in python would probably get much more messy.
In particular, it might require a new altChannel class, that looks like
a channel (i.e. send/receive methods) but actually encapsulates more
than one 'real' channel, or multiple underlying sends/receives per
communication. This might be interesting as a proof of concept, but is
not a long term solution.


Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list