35. Emptying the channel def empty_channel(channel): print 'tasklets waiting:', channel.balance while channel.balance > 0: value = channel.receive() print 'received', value stackless.tasklet(empty_channel)(channel) stackless.run()
36. Idiom: Blocking out of the scheduler rapture_channel = stackless.channel() def wait_for_rapture(): rapture_channel.receive() def call_me_when_rapture_occurs(): while rapture_channel.balance < 0: rapture_channel.send(None)