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"