[Stackless] API suggestions

Oren Tirosh oren-slp at hishome.net
Wed Mar 26 11:23:29 CET 2003


1. Represent each channel with two separate objects - one for the 
sender and one of the receiver side. The reference counts of the 
two objects are tracked separately. This can be useful for debugging: 
a tasklet will not block on sending to a channel with no receivers 
or attempting to receive from a channel with no senders. Instead 
an exception will be raised immediately.

2. I think it would be nice if channels supported the standard Python 
iteration protocol. On the receiver side all it takes is adding an 
__iter__() method returning self and making next() an alias for 
receive().  On the sender side a convenience method called 'stop' or
'end' would be equivalent to send_exception(StopIteration). 

3. Standard ways to start common tasklet/channel patterns:

Producer pattern: tasklet function gets a send channel as argument. 
Return value is the receive side of this channel. This is equivalent 
to generator functions except that the tasklet is allowed to pass on 
the send channel while a generator function can only yield from same 
frame.

Consumer pattern: tasklet function gets a receive channel as argument.
Return value is send side of same channel.

Filter pattern: tasklet function gets input and output channels as 
arguments. Return value is a tuple of two channels.

These patterns do not expose the actual tasklet object and concentrate 
on the data flow.


These suggestions will not replace the current API. It will be kept
as the low-level API for anyone that needs a finer level of control.
But for most uses I think a higher level API like this would be more
appropriate.

    Oren

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




More information about the Stackless mailing list