Accessing thread variables
Stuart Bishop
zen at shangri-la.dropbear.id.au
Wed Feb 19 06:16:30 EST 2003
On Wednesday, February 19, 2003, at 09:21 PM, Lukas Kubin wrote:
> What's the best way to access a thread's variable?
> Let's say I have thread:
>
> class MyThread(threading.Thread):
> def __init__(self):
> threading.Thread.__init__(self)
> self.varToReturn = ""
> self.start()
>
> def run(self):
> self.varToReturn = myAction()
>
> def myAction():
> string = "hello"
> return string
>
> And I call the thread:
>
> i = MyThread()
> print i.varToReturn
>
> This returns nothing (the empty string) instead of "hello".
> What am I doing bad?
i = MyThread()
i.join() # Wait for the thread to finish
print i.varToReturn
--
Stuart Bishop <zen at shangri-la.dropbear.id.au>
http://shangri-la.dropbear.id.au/
More information about the Python-list
mailing list