[Stackless] Blocked Tasklets

Richard richard at ccpgames.com
Wed Nov 30 15:31:18 CET 2005


I have no idea what the tasklet run method does.  I would use the
scheduler run method.  Code follows.

Here is the output when your code is rewritten to use this:

>>> Test()
0
Sending 0
getting 0
Sending 1
getting 1
Sending 2
getting 2
Sending 3
getting 3
Sending 4
getting 4
Sending 5
getting 5
Sending 6
getting 6
Sending 7
getting 7
Sending 8
getting 8
Sending 9
getting 9
Sending 10
getting 10
Sending 11
getting 11
Sending 12
getting 12
-1
>>>

Here is the rewritten code:

def Test():
    def Move(movechan):
        for n in range(13):
            print "Sending %r" % (n)
            movechan.send(n)
    def Move2(movechan2):
        x=0
        while x<>14:
            x = movechan2.receive()
            print "getting %r" % (x)
    ch2=stackless.channel()
    print ch2.balance
    # Schedule the sending tasklet.
    stackless.tasklet(Move)(ch2)
    # Schedule the receiving tasklet.
    stackless.tasklet(Move2)(ch2)
    stackless.run()
    print ch2.balance

Test()

-----Original Message-----
From: stackless-bounces at stackless.com [mailto:stackless-bounces at stackless.com]On Behalf Of Benjamin Buco
Sent: Tuesday, 29 November 2005 1:50 a.m.
To: stackless at stackless.com
Subject: [Stackless] Blocked Tasklets


Well, I found stackless a few weeks ago and its helping out a great deal so far.  However I seem to be a bit confused about when a channel unblocks a tasklet.  For some reason I thought that a tasklet blocked while waiting on a channel and then immediatly began to run itself again after being unblocked.  Here's my code, its pretty obvious what I want it do do, but these are the results I get:

0
Sending 0
getting 0
-1
-1

Any help would be greatly appreciated.
Thanks,
Benjamin Buco

Code Follows

def Test():
    def Move(movechan):
        for n in range(13):
            print "Sending %r" % (n)
            movechan.send(n)
    def Move2(movechan2):
        x=0
        while x<>14:
            x = movechan2.receive()
            print "getting %r" % (x)
    ch2=stackless.channel()
    print ch2.balance
    a2=stackless.tasklet(Move)(ch2)
    a2.run()
    a2=stackless.tasklet(Move2)(ch2)
    a2.run()
    print ch2.balance
    x=0
    print ch2.balance
Test()


Yahoo! Music Unlimited - Access over 1 million songs. Try it free.

_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless



More information about the Stackless mailing list