thread return code

Peter peter.milliken at
Tue Jan 19 23:07:46 CET 2010

On Jan 19, 9:25 pm, "Alf P. Steinbach" <al... at> wrote:
> * Rajat:
> > Hi,
> > I'm using threading module in Python 2.6.4. I'm using thread's join()
> > method.
> > On the new thread I'm running a function which returns a code at the
> > end. Is there a way I access that code in the parent thread after
> > thread finishes? Simply, does join() could get me that code?
> join() always returns None.
> But you can store the code in the thread object, and then access it after the
> join().
> Cheers & hth.,
> - Alf

The typical way to communicate with a thread is via a queue or pipe.
You can do what Alf suggests or you could create a queue (or pipe),
pass it to the thread as an argument and have the thread put the
"return value" into the queue as the last action prior to exit. After
the join() just read the results from the queue.

Using a queue or pipe is just a suggestion, the multiprocessing module
offers numerous ways to communicate between tasks, have a read and
pick whatever mechanism seems appropriate for your situation.


More information about the Python-list mailing list