[Stackless] Access to local variables of a task from tasklet

Najem Karim najemkarim at yahoo.com
Fri Jun 19 07:46:25 CEST 2009


Thanks,

I know the advantage of channels but I have a different scenario
to deal with. I have to run only one tasklet at a time i.e
I do the scheduling by myself. The first tasklet myTasklet1
is the main one and it must be executed step by step (this is why run(1))
and when it returns, I check some conditions to see
if I have to run the second tasklet, when yes I remove myTasklet1 from the list and create and start the second tasklet myTasklet2 until its done.
The problem is that myTasklet2 needs information about the status of myTasklet1 (i.e. some local variables). I never intend to use channels, by the way since it does not fit in my concept.

many thanks anyway,
Karim

--- Jeff Senn <senn at maya.com> schrieb am Do, 18.6.2009:

> Von: Jeff Senn <senn at maya.com>
> Betreff: Re: [Stackless] Access to local variables of a task from tasklet
> An: "Najem Karim" <najemkarim at yahoo.com>
> CC: stackless at stackless.com
> Datum: Donnerstag, 18. Juni 2009, 14:53
> 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 at stackless.com
> > http://www.stackless.com/mailman/listinfo/stackless
> >
> 
> 


      




More information about the Stackless mailing list