[Stackless] Difference between stackless.run() and tasklet.run()?

Bin Huang bin.arthur at gmail.com
Thu Jun 13 00:31:50 CEST 2013


Hi list,

While I was learning the Stackless, I noticed a nuance between
executing two pieces of code which are very similar.


The first piece of code from [1] is as follows:

>>> def f():
...     while 1:
...             print id(stackless.current)
...             stackless.schedule()
...
>>> t1 = stackless.tasklet(f)()
>>> t2 = stackless.tasklet(f)()
>>> t3 = stackless.tasklet(f)()
>>> t1.run()
29524656
29525936
29526512


The second piece of code from [2] is as follows:

>>> def InfiniteLoop(i):
...        while 1:
...            stackless.schedule()
...            print "schedule", i
...
>>> stackless.tasklet(InfiniteLoop)(1)
>>> stackless.tasklet(InfiniteLoop)(2)
>>> stackless.run()
schedule 1
schedule 2
schedule 1
schedule 2
...


The difference between outputs is that the first code can exit from
while(1) loop while the second code cannot. I suspect there is a
difference between stackless.run() and tasklet.run() but I could not
find any good documentation on this. I hope someone can give me some
hints.

Thanks in advance!

[1] http://www.disinterest.org/resource/stackless/2.6-docs-html/library/stackless/tasklets.html#tasklet.run
[2] http://www.stackless.com/wiki/Scheduling


Bin Huang



More information about the Stackless mailing list