Hi Najem:

>Message: 2
>Date: Thu, 18 Jun 2009 07:49:56 +0000 (GMT)
>From: Najem Karim <[email protected]>
>To: [email protected]
>Subject: [Stackless] Access to local variables of a task from tasklet
>Message-ID: <[email protected]>
>Content-Type: text/plain; charset=utf-8

>I have the following question: Is there a way to access the local >variables 
>of a tasklet.

Short answer, yes.

>I will explain with an example:

>myTasklet1 = stackless.run(1)

I believe this runs after one Python bytecode operation.

>I need this because at this point I would like to run another task which
>needs the current value localvar1 as input parameter

...

>Is there a way to do this.
>I appreciate any help.

If I understand what you want, I would suggest you use channels to help 
synchronize/schedule and perhaps pass values.

example

def mytasklet1():
    localVar = something
    while (someCondition):
        channel = stackless.channel()
        stackless.tasklet(mytasklet2)(channel, localVar)
        returnValue = channel.receive()  # mytasklet will wait
        .....

def mytasklet2(channel, localVar):
    # do something with localVar
    #...
    channel.send(someValue)

if __name__ == "__main__":
   stackless.tasklet(mytasklet1)()
   stackless.run()

Hope this helps.

Cheers,
Andrew


      

_______________________________________________
Stackless mailing list
[email protected]
http://www.stackless.com/mailman/listinfo/stackless

Reply via email to