retrieving a return code from a thread

J

Jean-Yves Nief

hi all,

I would like to know how I can retrieve in my main program the
return code from a thread that I launched:
class example(threading.Thread):

def __init__(self, filename):
self.filename = filename
threading.Thread.__init__(self)
self.start()

def run(self):
........
rc = os.system("command example")

in the main thread:
......
thrdExample = []
thrdExample.append(example(file))
......
# once it's not active anymore, test of the return code for
thrdExample ??

thanks in advance,
JY
 
D

Diez B. Roggisch

You could use a synchronized Queue (look into the docs) where the running
thread(s) put their results. The main loop waits until some or all results
are there, and then continues processing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top