By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,923 Members | 1,655 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,923 IT Pros & Developers. It's quick & easy.

how to get the return value of a thread?

P: n/a
Dear all,

i would like to get the return value of all threads

e.g.
def foo(num):
if num>10:
return 1
elif num>50:
return 2
else
return 0
after i invoked
t = thread.start_new_thread(foo,(12,))
how to get the return value of `foo'?

Thanks

--
Best Regards,
Leo Jay
Sep 9 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Leo Jay wrote:
Dear all,

i would like to get the return value of all threads

e.g.
def foo(num):
if num>10:
return 1
elif num>50:
return 2
else
return 0
after i invoked
t = thread.start_new_thread(foo,(12,))
how to get the return value of `foo'?


Take a look at the Queue module. Create a queue instance at let the 'foo
thread' put() its result into it:

fooResult = Queue.Queue()

def foo(num):
result = 0

if num>10:
result = 1
elif num>50:
result = 2

fooResult.put(result)

t = thread.start_new_thread(foo,(12,))

# do other stuff, foo is running in background

r = fooResult.get() # guaranteed to block until result is available
print r

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
Sep 9 '05 #2

P: n/a
Op 2005-09-09, Leo Jay schreef <py***********@gmail.com>:
Dear all,

i would like to get the return value of all threads

e.g.
def foo(num):
if num>10:
return 1
elif num>50:
return 2
else
return 0
after i invoked
t = thread.start_new_thread(foo,(12,))
how to get the return value of `foo'?

Thanks


Maybe you should have a look at the Future class
http://aspn.activestate.com/ASPN/Coo...n/Recipe/84317

--
Antoon Pardon
Sep 12 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.