How can I wait for all the threads I spawn for 5 minutes
Fabio Z Tessitore
fabioztessitore at libero.it
Mon Sep 3 12:02:08 EDT 2007
> [cut]
> 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?
I've written a little code for you using threading. Hope it will help you:
#! /usr/bin/env python
# -*- coding: utf8 -*-
import threading
import time
class MyLittleThread(threading.Thread):
def __init__(self):
threading.Thread.__init__(self)
def run(self):
time.sleep(5)
if __name__ == "__main__":
# create a list of 10 MyLittleThread
# total time to wait is 5 sec (NOT 5sec*10)
lt = []
for i in range(10):
lt.append(MyLittleThread())
for th in lt:
th.start()
bye
More information about the Python-list
mailing list