[Stackless] priority patch

Kristján Valur Jónsson kristjan at ccpgames.com
Thu Nov 5 21:11:59 CET 2009

Yes, with t.priority=True, starvation _can_ occur.  consider this:
def foo():
	while True:
		print stackless.getcurrent()

a = stackless.tasklet(foo)
b = stackless.tasklet(foo)

tasklet A would be the only one to ever run.
This is why one needs to be careful with 'priority'.  In fact, I don't have a use case for settin the flag to 'true' at all, I just added it because it is possible.  My use cases all focus on "tasklet.boost()" which gives a tasklet additional priority for one scheduling round.  This way it can wake up before other tasklets to service an important interrupt request.

I plan on trying to do this in a slightly different manner now.  As a first step, I'll abstract away the current round-robin scheduling behind some central scheduling API so that we can then later add stuff such as priority without modifying other parts of Stackless.  As it is, scheduling behaviour is defined in various places throughout the code and that makes analysing it somewhat tricky.

p.s. What do people say about changing the tasklet's "setup" function to return 'self'?  That way one can write
a = stackless.tasklet(foo)()
which is more concise than

Stackless has been unchanged for some years now, and I do think we need to keep it alive by continuing its development, adding features, perhaps creating a stackless.tools module, etc.

> -----Original Message-----
> From: Andrew Francis [mailto:andrewfr_ice at yahoo.com]
> Sent: 5. nóvember 2009 17:38
> To: stackless at stackless.com
> Cc: Kristján Valur Jónsson
> Subject: Re: priority patch
> Hello Kristjan:
> >If no one objects too strongly to this I'm hoping to get this accepted
> >into the trunk.
> I would have to examine your algorithm in more detail. This takes
> time. I have been reviewing your StacklessIO EVE-Online stuff.
> I have being going over scheduling algorithms in general. And
> reading the Pike and Cardelli works on rendezvous communications.
> Gut reaction: I am not sure if tasklet priority and rendezvous
> semantics mix well. Also, when I see tasklet priority, the first
> thing I look at is whether starvation could occur.
> That said, I would recommend that you test these ideas out in PyPy.
> PyPy will be the place I will test new algorithms and feature.
> As for the trunk. It is your show. I guess if I feel uncomfortable with
> tasklet priority, I won't use it.
> Cheers,
> Andrew

More information about the Stackless mailing list