Tim Williams (gmail) tdwdotnet at
Tue Jun 29 21:20:02 CEST 2004

On Tue, 29 Jun 2004 14:36:50 -0400, jesso1607 at
<jesso1607 at> wrote:
> I want to get results from a thread from the main thread.  In C I would use pthread_join to wait for the thread and access the result in a paramter I passed to pthread_join.
> In python I can wait with join, but how would you get a result from the thread?
> Thanks for any help,
> Jason

You could pass the new thread a queue  and wait for the new thread to
put something on the queue

import Queue

q_in = Queue.Queue()  #create an inbound queue from the worker threads
thread.start_new_thread(queue_worker, (q_in))  
w = q_work.get(1)   # wait for reply from worker thread
#do something with w

def queue_worker(q_in):
        #do something resulting in w
        q_in.put(w)      # pass reply back to queuethread


More information about the Python-list mailing list