This simplest way to do this is to use a channel -- in fact it's
pretty much exactly why they exist -- that is: so you don't have
to think about the scheduling of (and race-conditions between)
communicating tasklets:
--------------
import stackless
chan1 = stackless.channel()
def myTask1(chan):
# stuff...
localVar1 = "something"
chan.send(localVar1)
x = chan.receive() #block until t2 tells us to resume
# stuff...
def myTask2(chan):
myLocal = chan.receive()
# stuff...
chan.send(None) #resume task 1
stackless.tasklet(myTask1)(chan1)
stackless.tasklet(myTask2)(chan1)
stackless.run()
-----
Or you could make a more general recipe by using 2 channels (myTask1
makes
a new channel to resume and sends the channel with localVar1 to
myTask2).
Pardon me if you were contemplating something more sneaky and
this was too obvious...
-Jas
On Jun 18, 2009, at 3:49 AM, Najem Karim wrote:
Hello,
I have the following question:
Is there a way to access the local variables
of a tasklet.
I will explain with an example:
I have a task say:
def myTask1()
localvar1 = 10
....
I use it to create a tasklet say:
myTasklet1 = stackless.tasklet(myTask1)()
then run it with:
myTasklet1 = stackless.run(1)
to run one instruction and return.
Is possible now to use myTasklet1 to check/get the value of localvar1
I need this because at this point I would like to run another task
which
needs the current value localvar1 as input parameter
say:
def myTask2(var1)
....
pass
Now get the value of localvar1 from myTasklet1 and store it in var1
then remove myTasklet1 from the list using:
myTasklet1.remove()
then create and run the second tasklet untill the end using:
myTasklet2 = stackless.tasklet(myTask2)(var1)
stackless.run()
Once myTasklet2 is done, I resume myTasklet1 were it stopped before
using
myTasklet2.insert()
myTasklet1 = stackless.run(1)
then repeat allover again until myTasklet1 is finished
Is there a way to do this.
I appreciate any help.
Thanks
_______________________________________________
Stackless mailing list
Stackless@stackless.com
http://www.stackless.com/mailman/listinfo/stackless
_______________________________________________
Stackless mailing list
Stackless@stackless.com
http://www.stackless.com/mailman/listinfo/stackless