All pastes #297081 Raw Edit

Untitled

public text v1 · immutable
#297081 ·published 2006-12-30 20:50 UTC
rendered paste body
import urllib
MAX_THREADS = 5
THREAD_POOL = []
URL_LIST = [ "http://www.google.ca/intl/en_ca/images/logo.gif"]

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

def open(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"
                        open(myurl,THREAD_POOL.pop())
                else:
                        print "Waiting for a free spot in the thread pool"