[Stackless] walking off the end of a channel

Matt Provost mprovost at termcap.net
Thu Apr 19 07:25:42 CEST 2007

I found out that if you receive() on a channel until it's finished, then
it appears that the receiving tasklet dies. I'm not sure if it detects a
deadlock and kills it, or what I should do about it.

Here's some example code:

import stackless
ch = stackless.channel()

def sequence_send(channel):

def iter_send(channel):
        x = 0
        while x < 10:
                x = x + 1

def iter_receive(channel):
        for x in xrange(10):
                y = channel.receive()
                print y
        print "done!"

def sequence_receive(channel):
        for y in channel:
                print y
        print "done!"


If you run the sequence_send and sequence_receive tasklets, it will
print 0 through 9, but not "done!". iter_receive works, but only if it
loops less than or equal to the number of messages sent across the
channel. If you change xrange(10) to xrange(11), it won't print "done!"

The program itself doesn't die, you can put something after
stackless.run() and it will work.

I just noticed this because usually my tasklets just loop over a
channel, but I wrote one that does some cleanup afterwards and that code
isn't being executed. It seems like this should work, but maybe I'm
missing something? What other way is there to accomplish this?


Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list