With Stackless ou get tasklets and channels. Channels let you communicate between tasklets.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env stackless | |
import stackless | |
def sendKidsToShops(): | |
kids = 3 | |
ch.send(kids) | |
print kids, "kids sent to the store" | |
def buySweeties(): | |
n = ch.receive() | |
while n: | |
print "kid #", n, "is spending your money on candy." | |
n -= 1 | |
#stackless.schedule() | |
ch = stackless.channel() | |
stackless.tasklet(sendKidsToShops)() | |
stackless.tasklet(buySweeties)() | |
stackless.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kid # 3 is spending your money on candy. | |
kid # 2 is spending your money on candy. | |
kid # 1 is spending your money on candy. | |
3 kids sent to the store |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
kid # 3 is spending your money on candy. | |
3 kids sent to the store | |
kid # 2 is spending your money on candy. | |
kid # 1 is spending your money on candy. |
See my next post An Alternate Explanation of Continuations
Good luck fellow travellers.
No comments:
Post a Comment