[Stackless] question on preemtive scheduling semantics

Mads Darø Kristensen madsdk at gmail.com
Thu Mar 19 09:43:05 CET 2009


Hi Paul.

Paul Sijben wrote:
> I believe all of my tasklets do not block for too long a time, however I
> need to be certain that they do not block the others.
>
> Do I understand correctly that if I start scheduling using
> stackless.run(10000) tasklets that run short enough will not see any
> difference. But tasklets that need more instruction will be stopped
> after 10000 instructions simply be resumed at the place where they were
> interupted? Or are they simply killed for running too long?

The stackless.run(x) method returns the tasklet that was currently 
executing when the 'x' limit was reached. If you want the tasklet to be 
resumed you need to manually reinsert it into the scheduling queue. Example:

while stackless.getruncount() > 0:
     tasklet = stackless.run(10000)

     # Here you may do whatever it is you need to do every 10.000
     # instructions...

     if tasklet:
         tasklet.insert()

This small snippet of code will execute all tasklets until the queue is 
empty.

Best regards
Mads Kristensen




More information about the Stackless mailing list