[Stackless] Semantic of schedule_remove
Alberto Ganesh Barbati
AlbertoBarbati at libero.it
Wed May 21 18:59:56 CEST 2008
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
More information about the Stackless
mailing list