[Stackless] Suggestions about Customizing Channels with Composition rather than Inheritance

Andrew Francis andrewfr_ice at yahoo.com
Sat Dec 9 17:34:07 CET 2006

Hello Colleagues:

I have been looking at Richard Tew's Wiki suggestions
about customising channels and tasklets (i.e.,
providing names). The examples are very useful.

Since I am haven't come up to speed concerning
pickling, I thought it would be is easier to use
composition. For example here is an example of a
channel class, ProcessorChannel that takes a name and
provides two new methods for attaching and detaching
tasklets to and from channels.  I wrote
ProcessorChannel to make it easier to swap inactive
"tasklet groups" in and out of memory. 

Comments would be appreciated. If this approach is
sound, I will write up a Wiki page.


#!/usr/bin/env python

ProcessorChannel is a wrapper for the stackless
Two differences

1. Name
2. Methods to make attaching and detaching the channel
from its tasklets easier.


import stackless

class ProcessorChannel(object):
    def __init__(self, name = None):
        self.name = name
        self.channel = stackless.channel()
        self.tasklets = []
    def __repr__(self):
        return self.name 
    get the underlying channel's balance
    def getBalance(self):
        return self.channel.balance
    def attach(self):
        x, y, (balance, flags, waste) =
        self.channel.__setstate__((balance, flags,
    def detach(self):
        x, y, (balance, flags, self.tasklets) =
        self.channel.__setstate__((balance, flags,
    def receive(self):
        return self.channel.receive()
    def send(self, message):
    balance = property(getBalance)

Do you Yahoo!?
Everyone is raving about the all-new Yahoo! Mail beta.

Stackless mailing list
Stackless at stackless.com

More information about the Stackless mailing list