All pastes #297092 Raw Edit

Untitled

public text v1 · immutable
#297092 ·published 2006-12-30 20:58 UTC
rendered paste body
import urllib

MAX_THREADS = 5
THREAD_POOL = []
URL_LIST = [ "http://www.google.ca/intl/en_ca/images/logo.gif"]
import time
import threading

for i in range(0,MAX_THREADS):
        THREAD_POOL.append(i)

def openurl(myurl, ID):
        urllib.urlopen(myurl)
        THREAD_POOL.append(ID)

print THREAD_POOL
while 1:
        for i in URL_LIST:
                if len(THREAD_POOL) > 0:
                        print "Thread started. Getting " + i
                        threading.Thread(target=openurl,args=(i,THREAD_POOL.pop())).start()
                else:
                        pass
                        #print "Waiting for a free spot in the thread pool"