Source

multithreading / src / ex20.py

Gennadiy Zlobin 1c12779 


















import Queue
import threading
import urllib

def geturl(q, url):
    q.put(urllib.urlfetch(url).read())

theurls = '''http://example.com/be
             http://example.de/bi
             http://example.co.uk/bo'''.split()

q = Queue.Queue()

for u in theurls:
    t = threading.Thread(target=geturl, args=(q, u))
    t.daemon = True
    t.start()

s = q.get()
print s