473,795 Members | 3,048 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

how to get the return value of a thread?

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_ne w_thread(foo,(1 2,))
how to get the return value of `foo'?

Thanks

--
Best Regards,
Leo Jay
Sep 9 '05 #1
2 25675
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_ne w_thread(foo,(1 2,))
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(r esult)

t = thread.start_ne w_thread(foo,(1 2,))

# 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
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_ne w_thread(foo,(1 2,))
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
1704
by: Tee | last post by:
Hi, Can we use thread.start on a function that has return value? I have a function that will take sometimes to run and it will return a string value, and I want to use thread.start to call this function and get the string, is this possible? Thanks,
1
2622
by: Tropos | last post by:
Query: Will a MutexGuard object release before a function return value is copied? Consider the C++ code: class MutexGuard //A familiar sort of class for making mutexes exception-safe { . . . ~MutexGuard(); //releases the mutex when the stack pops
8
3083
by: DaKoadMunky | last post by:
Please consider the following... <CODE> #include <string> using namespace std; typedef int PrimitiveType; typedef string ClassType;
3
1691
by: Felix Kater | last post by:
Hi, normally I use a local variable assigned to different return values inside the function and return it like this: int f(){ int my_err_code; my_err_code=1;
22
4046
by: semedao | last post by:
Hi , I am using asyc sockets p2p connection between 2 clients. when I debug step by step the both sides , i'ts work ok. when I run it , in somepoint (same location in the code) when I want to receive 5 bytes buffer , I call the BeginReceive and then wait on AsyncWaitHandle.WaitOne() but it is signald imidiatly , and the next call to EndReceive return zero bytes length , also the buffer is empty. here is the code: public static byte...
3
1493
by: chance | last post by:
I want my thread method to return a String. However, the compiler is saying that the best overloaded method match for System.Threading.Thread has some invalid arguments. Not sure what I need to change here. public String generateNOV(string xmlParms) { Thread novThread = new Thread(delegate() tia,
1
3476
by: Chris Roth | last post by:
I've been working with boost::threads to do some multithreading in my code and have run into some questions that I haven't been able to find answers to. I'll include some sample code to illustrate my questions. #include <boost/thread/thread.hpp> #include <iostream> using namespace std;
7
10326
by: Terry Olsen | last post by:
How do I get this to work? It always returns False, even though I can see "This is True!" in the debug window. Do I have to invoke functions differently than subs? Private Delegate Function IsLvItemCheckedDelegate(ByVal ClientID As Integer) As Boolean Private Function IsLvItemChecked(ByVal ClientID As Integer) As Boolean If lvServers.InvokeRequired = True Then lvServers.Invoke(New IsLvItemCheckedDelegate(AddressOf IsLvItemChecked),...
4
6078
by: vishal1082 | last post by:
okay so i have this situation: i have to get round trip time (ping) from a IP, but if i do it in the UI thread it freezes if the ping is high, for example > 300, now to stop the UI to hang i made the ping in another thread, but how can i return value from the 2nd thread(the one pinging)?, i cant directly change the label because this code is in a dll, also even if i use delegates to make new thread (that support return value) the first thread...
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10001
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6783
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.