以下程序如何在不调用程序中的A.fun
的情况下执行我的成员stackless.run()
?
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)
输出:
hi 6