[Stackless] Beginner

Cristiano Paris frodo at theshire.org
Tue May 30 15:57:49 CEST 2006


Hi everyone,

I started playing with stackless but I'm a bit confused by how it really 
works.

Consider the following code snippet:

-----
import stackless as slp

def taskPrint(x):
   while 1:
     print x + "1"
     slp.schedule()
     print x + "2"
     slp.schedule()

t1 = slp.tasklet(taskPrint)
t2 = slp.tasklet(taskPrint)
t3 = slp.tasklet(taskPrint)

t1.setup("A")
t2.setup("B")
t3.setup("C")

theTasklet = t1

while 1:
   print "Before theTasklet.run()"
   theTasklet.run()
   print "After theTasklet.run()"
-----

When I run this script I get:

Before theTasklet.run()
A1
B1
C1
After theTasklet.run()
Before theTasklet.run()
A2
B2
C2
After theTasklet.run()
Before theTasklet.run()
A1
B1
C1
After theTasklet.run()
Before theTasklet.run()
A2
B2
C2
...

which makes sense since slp.schedule() calls the next runnable taskletin 
the global queue.

Conversely, if I put theTasklet = t2 I get:

Before theTasklet.run()
B1
C1
After theTasklet.run()
Before theTasklet.run()
B2
C2
After theTasklet.run()
Before theTasklet.run()
B1
C1
...

and t1 never gets called. This makes me think that if we think of 
tasklets as being in a queue, calling run() on one of them will run any 
other tasklets till the end of the queue (but task before it are never 
called).

What if I wanted to run JUST the tasklet I called run() upon? That is, 
if theTasklet = t1, calling t1.run() (or whatever) should result in:

Before theTasklet.run()
A1
After theTasklet.run()
Before theTasklet.run()
A2
After theTasklet.run()
Before theTasklet.run()
A1
After theTasklet.run()
Before theTasklet.run()
A2
After theTasklet.run()
...

Thank you,

Cristiano

_______________________________________________
Stackless mailing list
Stackless at stackless.com
http://www.stackless.com/mailman/listinfo/stackless



More information about the Stackless mailing list