How can I wait for all the threads I spawn for 5 minutes

Antoon Pardon apardon at forel.vub.ac.be
Mon Sep 3 09:43:20 EDT 2007


On 2007-08-31, herman <Herman.Schultz at gmail.com> wrote:
> Hi,
>
> In my python program, I would to like to spwan 5 threads, for the them
> for 5 minutes maximum and the continue. Here is my script:
>
>             threads = []
>
>             for j in range(5):
>                 t = MyThread()
>                 threads.append(t)
>
>             for t in threads:
>                 t.join(60*5)
>                 print "thread join\n"
>
>             # wait for 5 minutes for all the threads to complete ,
> and
>             # then continue
>
> But this code ends up waiting 5 minutes for **each** thread.  that is
> not what I want. I just want to wait for 5 minutes for all threads.
> how can I do that?
>
> And after 5 minutes, i want to kill off all the threads I spawn
> earlier, how can I do that in python.

You may wish to look at this. No guarantee though.

  http://groups.google.com/group/comp.lang.python/browse_thread/thread/2002d29c965534cc/5833130893cee567?lnk=st&q=&rnum=2&hl=nl#5833130893cee567



More information about the Python-list mailing list