Idle wait for outstanding threads?

Alan Kennedy alanmk at hotmail.com
Thu Jan 31 06:41:30 EST 2002


aahz at panix.com (Aahz Maruch) wrote in message :
> Alan Kennedy <alanmk at hotmail.com> wrote:
> >
> >From a main thread, I start a number of threads to execute some
> >service, say some database queries. I want the main thread to wait
> >until all of the service threads are complete before continuing.
> 
> Erno gave you the simple/correct response, but if you explained why you
> want the main thread to wait for *all* the subthreads (rather than
> processing results as they come in), you might get a better answer.

Erno, Thanks, I see now that I need to be looking at using the
threading module instead of the thread module.

Aahz, basically, what I am trying to do is parallelise a number of
function calls that are made in order to service a request. To service
a request, I need to carry out some actions

def serviceRequest(req):
    # Task: Carry out database query 1
    # Task: Carry out database query 2
    # Task: Carry out database query 3
    # Task: Carry out some complex calculations
    # Collate the results and prepare the reply

Now all of the tasks carried out above are independent, so they can be
executed in parallel. So I hope to speed things up by creating a
thread for each one. Obviously, I have to wait until all of the tasks
are finished before I collate the results and prepare the reply.

I've coded myself a little sample program that uses
'threading.Thread's and 'join's and it works just fine. However, it is
consuming *massive* amounts of memory.

I'm going to start a new thread about the memory consumption.

Thanks for the help,

Alan.



More information about the Python-list mailing list