[Stackless] Approaches Re: About Adding Features to Stackless
Andrew Francis
andrewfr_ice at yahoo.com
Tue Mar 23 18:39:21 CET 2010
Hi Christian:
--- On Sun, 3/21/10, Christian Tismer <tismer at stackless.com> wrote:
> I think it is good to leave things as Python prototype as
> is it possible. Turning things into C removes flexibility,
> and ties it to Stackless' implementation, which is still
> questionable for me.
One of the reasons I am doing this exercise is to get my
hands dirty with the internals of Stackless Python. This is an
area where I have shied away from. Also I wanted to see why
Stackless could not implement a Go/Newsqueak/Limbo style select/alt mechanism. Finally I could use this feature.
> If you must have it for speed, well, you can add it to
> the stackless module,
Well Christian, I think a select style mechanism is a natural
throughput increaser (easier to service channels in a timely
fashion) and resource saver (don't need addition tasklets to
simulate select()).
>or better provide your own module. Do you think it is possible to
>add the functionality, or do you have to change a lot?
As I stated in the previous post, I have played with select as a
method (stackless.select) and as class (an EventHandler).
I think the best approach to putting a select feature into Stackless
is put just enough hooks into Stackless to allow the feature to be
implemented as a module. In this fashion, folks that don't want a
select, don't need to pay for it. And folks that want it, can choose.
The key concept is that from the point of view of a tasklet that
rendez-vous with a channel controlled by a select, it sees no difference. Robert Pike makes this point in his "Implementation of Newsqueak" paper. To ensure this transparency, I believe these are the minimum changes:
1) Since channels and channel balances are computed, a tasklet needs a way of putting itself on a channels queue and changing the balance accordingly,
without blocking. Otherwise, the tasklet cannot place itself on multiple
channels before calling a schedule_remove() and schedule().
I found manipulating channels with __reduce__ caused crashes. So I would add a method to channel - addOperation(self, tasklet, operation) where operation is {RECEIVE | SEND}.
2) When the tasklet that invoked the select mechanism gets called, it needs to know what channel is ready. This matters only if you plan to the programme level to take some action, for example:
# eventHandler is one of the classes I am playing with
# i like this because it means I don't change how tasklets work.
channel, operation, value = eventHandler.wait()
if channel == GUI:
....
elif channel == NETWORK:
....
elif channel == TIMEOUT:
....
>From my understanding, I can use tasklet._channel to determine which
channel the tasklet was blocked on. I believe channel_action() controls
the setting of this attribute. I am not sure what the _channel getter
needs to tranverse a list? I have to re-read the code to confirm
this. If you (or anyone else) can give me insights, that would be
great.
Once I finish prototyping in Python, it will take me a while to
get used to reading and playing with the C code and making the changes
to see if these ideas really work.
Cheers,
Andrew
More information about the Stackless
mailing list