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

herman Herman.Schultz at gmail.com
Fri Aug 31 19:40:46 EDT 2007


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.

Thank you for any help.




More information about the Python-list mailing list