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

Andrew Francis andrewfr_ice at yahoo.com
Thu Jun 18 16:11:35 CEST 2009

Hi Najem:

>Message: 2
>Date: Thu, 18 Jun 2009 07:49:56 +0000 (GMT)
>From: Najem Karim <najemkarim at yahoo.com>
>To: stackless at stackless.com
>Subject: [Stackless] Access to local variables of a task from tasklet
>Message-ID: <590475.43759.qm at web24501.mail.ird.yahoo.com>
>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.


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

if __name__ == "__main__":

Hope this helps.



More information about the Stackless mailing list