Channels send regular Python links, so the data you send (channel, string, whatever) is exactly what you received.
One example of sending a channel on a channel is when you use the tasklet as a service, i.e. the tasklet listens for the request channel, does the work, and returns the result. The request must include data for operation and a return channel for the result, so that the result is transmitted to the requestor.
Here is an extreme example that I developed for my Stackless talk at PyCon a few years ago. This creates a new task for every function call, so I can use a recursive factorial implementation that does not need to worry about the Python stack limit. I allocate a tasklet for each call, and it receives a return channel for the result.
import stackless def call_wrapper(f, args, kwargs, result_ch): result_ch.send(f(*args, **kwargs)) # ... should also catch and forward exceptions ... def call(f, *args, **kwargs): result_ch = stackless.channel() stackless.tasklet(call_wrapper)(f, args, kwargs, result_ch) return result_ch.receive() def factorial(n): if n <= 1: return 1 return n * call(factorial, n-1) print "5! =", factorial(5) print "1000! / 998! =", factorial(1000)/factorial(998)
Output:
5! = 120 1000! / 998! = 999000
I have several other examples of channeling channels by channel in my presentation. This is a common thing in Stackless.
source share