透明思考


Transparent Thoughts


Is Stackless Python THE Way?

Code withStackless Python

## pingpong_stackless.py#import stacklessping_channel = stackless.channel()pong_channel = stackless.channel()def ping():while ping_channel.receive(): #blocks hereprint “PING”pong_channel.send(“from ping”)def pong():while pong_channel.receive():print “PONG”ping_channel.send(“from pong”)stackless.tasklet(ping)()stackless.tasklet(pong)()# we need to ‘prime’ the game by sending a start message# if not, both tasklets will blockstackless.tasklet(ping_channel.send)(‘startup’)stackless.run()

And it runs…forever.