Hi Folks:

As I stated in a previous post, I have written a new version of stackless.py 
incorporating a concept called join patterns. Join patterns build up on the 
work I have done with stackless.select(). I am still experimenting with the API 
amongst other things. So things look rough. When I get stuff stabilized, I'll 
post a new version of stackless.py in the stackless repository.


With the exception of a hiccup of a recursion limit problem (there is a weird 
interaction with Twisted), here is the core of the dining philosophers that 
roughly mimics the example in the paper "Scalable Join Patterns." I left out 
the Twisted parts.



def thinker(name, thinking, left, right):
    global pattern
    print "Philosopher %s left=%s right=%s" % (name, left.label, right.label)
    utensils = 
stackless.joinPattern([stackless.JoinReceiveChanop(left.receiveCase()), \
                                      
stackless.JoinReceiveChanop(right.receiveCase())])
    patterns.append(utensils)

    while True:
       waitTime = random.randint(thinking[0], thinking[1])
       print name, "thinking for ", waitTime, "time units"
       tick(waitTime)
       print name, "ready to eat"
       result = stackless.select([utensils])
       for p in result:
           print p.value, " relenquished chopstick ", p.channel.label

       utensils.reset()

       print name, " finished eating"
       release(left, name)
       release(right, name)


Since I didn't build buffered channels into the new stackless.py, I have to do 
asynchrony in the following way:

def release(aChannel, name):
    def __release():
        aChannel.send(name)
    stackless.tasklet(__release)()


I would appreciate feedback.

Cheers,
Andrew
_______________________________________________
Stackless mailing list
[email protected]
http://www.stackless.com/mailman/listinfo/stackless

Reply via email to