python program without stackless.run()

60 views Asked by At

How the below program execute my member A.fun without calling stackless.run() in the program?

import stackless

class A:
    def __init__(self,name):
        self.name = name
        self.ch = stackless.channel()
        stackless.tasklet(self.fun)()

    def __call__(self,val):
        self.ch.send(val)

    def fun(self):
       while 1:
         v = self.ch.receive()
         print "hi" , v


if __name__ == "__main__":
    obj = A("sh")
    obj(6)

output:

hi 6
1

There are 1 answers

0
o11c On

I've never used stackless, but I'm guessing from the documentation that calling channel.send makes the scheduler call the other tasklet.