home | show tags | navigation

switch to tags
switch to navbar

Coolness

Stackless Python is one of the coolest languages I’ve seen recently. To put it very (very) simply, it’s Python with coroutines. Take this example (stolen from here):

ping_channel = stackless.channel()
pong_channel = stackless.channel()

def ping():
    while ping_channel.receive(): #blocks here
        print "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)()

stackless.tasklet(ping_channel.send)('startup')

stackless.run()

As Grant Olson notes in his introduction, this program could be run for as long as you like and it would consume the same amount of memory and, theoretically, never crash. Incredible coolness. Of course this is only one nifty thing about Stackless, it has much more and everyone should look at it. It’s especially nifty for game development since you can use the “micro threads” to play around with concurrency without losing hair.

Tuesday, June 26th, 2007 at 5:03 amand is filed under programming, posted by cardi. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

Leave a Reply