[Stackless] Semantic of schedule_remove
Jeff Senn
senn at maya.com
Wed May 21 22:21:43 CEST 2008
Hi Alberto-
Check the doc string for stackless.schedule_remove
import stackless
print stackless.schedule_remove.__doc__
And then run this slightly modified example and see
if the behavior is more obvious to you. (Note: that
the "next runnable tasklet" could be yourself!
I suppose this boundary condition might be considered
a bit "astonishing".... :-)
-------
import stackless
def run(name):
print name, "start"
myself = stackless.getcurrent()
if stackless.schedule_remove() == myself:
print "No one else to switch to! Continuing..."
print name, "stop"
stackless.tasklet(run)("A")
stackless.tasklet(run)("B")
stackless.run()
On May 21, 2008, at 12:59 PM, Alberto Ganesh Barbati wrote:
> Hi,
>
> I was making a few experiments with
>
> Python 2.5.2 Stackless 3.1b3 060516 (release25-maint, Feb 23 2008,
> 16:55:33) [MSC v.1310 32 bit (Intel)] on win32
>
> and I stumbled on this code:
> ------
> import stackless
>
> def run(name):
> print name, "start"
> stackless.schedule_remove()
> print name, "stop"
>
> stackless.tasklet(run)("A")
> stackless.tasklet(run)("B")
> stackless.run()
> -----
>
> I was expecting to have this output:
> ------
> A start
> B start
> ------
>
> instead I got
> ------
> A start
> B start
> B stop
> ------
>
> the "B" tasklet was not removed as I expected. Actually it seems
> that schedule_remove() does not remove the last tasklet in queue.
> This can be seen by adding a dummy tasklet:
> ------
> import stackless
>
> def run(name):
> print name, "start"
> stackless.schedule_remove()
> print name, "stop"
>
> def dummy():
> print "dummy"
>
> stackless.tasklet(run)("A")
> stackless.tasklet(run)("B")
> stackless.tasklet(dummy)()
> stackless.run()
> -----
>
> which produces the output I would expect:
> -----
> A start
> B start
> dummy
> -----
>
> Notice that the "dummy" tasklet is added *after* the two "run"
> tasklets. If I added it *before*, the output would be "wrong" again:
> -----
> dummy
> A start
> B start
> B stop
> -----
>
> Is this the correct behaviour of schedule_remove() or a bug? If it's
> the correct behaviour I dare say it violates the Least Astonishment
> Principle and I would like to know which would be the rationale.
>
> Thanks in advance,
>
> Ganesh
>
>
> _______________________________________________
> Stackless mailing list
> Stackless at stackless.com
> http://www.stackless.com/mailman/listinfo/stackless
>
More information about the Stackless
mailing list