from threading import Thread, enumerate from urllib import urlopen from time import time class URLThread(Thread): def __init__(self,url): super(URLThread, self).__init__() self.url = url self.response = None self.setDaemon(True) def run(self): self.request = urlopen(self.url) self.response = self.request.read() def multi_join(threads, timeout=None): for thread in threads: start = time() thread.join(timeout) if timeout is not None: timeout -= time() - start return threads def multi_get(uris,timeout=2.0): def alive_count(lst): count = 0 for x in lst: if x.isAlive(): count += 1 return count threads = [ URLThread(uri) for uri in uris ] for thread in threads: thread.start() return [ (x.url, x.response) for x in multi_join(threads, timeout)]