[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):
        channel.send_sequence(xrange(10))

def iter_send(channel):
        x = 0
        while x < 10:
                x = x + 1
                channel.send(x)
                stackless.schedule()

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!"

stackless.tasklet(sequence_send)(ch)
#stackless.tasklet(iter_send)(ch)
stackless.tasklet(sequence_receive)(ch)
#stackless.tasklet(iter_receive)(ch)
stackless.run()

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!"
anymore.

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?

Thanks,
Matt

_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless



More information about the Stackless mailing list