ρss
ρss

Reputation: 5315

Getting the result of a particular thread in python

Level: Beginner

I am currently working with pythonv2.7 on windows 7 OS. I have a question regarding threads. I am actually working on an GUI app with wxPython and python. During my project I have a situation where I need to check some value from a server infinitely (Of course pausing for some time interval too). So in my programm I have a method X(self, code) that gets the value from the server. This method X(self, code) requires an argument called code. Depending upon the value of the argument code the server will return a value. Now I need to call this method X(self, code) infinitely with all possible values of the code to get all the values from the server so that my values are up to date. So, I thought of implementing threads, so that each thread will use a particular value of the code and use X(self, code) method to get the value from the server for that particular value of the code and return it. I have a problem in doing so. The threads are being created and returning values but I don't understand how can I get the results of a particular thread? I think that I not implementing a good logic. It would be nice if someone can suggest some thing better.

Upvotes: 0

Views: 71

Answers (1)

Alvaro
Alvaro

Reputation: 2327

Regarding your question, and not entering in the correctness of your solution.

The Thread objects have a name attribute that identifies the thread. Therefore, you can use:

print "%s Whatever" % self.name

in your print statements (or even better, create a print method that prepends the thread name and use that instead).

Upvotes: 1

Related Questions