threading

Tim Williams (gmail) tdwdotnet at gmail.com
Tue Jun 29 15:20:02 EDT 2004


On Tue, 29 Jun 2004 14:36:50 -0400, jesso1607 at rogers.com
<jesso1607 at rogers.com> 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

EG
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