View difference between Paste ID: pVLSiNW2 and eYe7MCKn
SHOW: | | - or go back to the newest paste.
1
import threading
2
import urllib2
3
import time
4
5
start = time.time()
6
urls = ["http://www.google.com", "http://www.apple.com", "http://www.microsoft.com", "http://www.amazon.com", "http://www.facebook.com"]
7
8
def fetch_url(url):
9
    urlHandler = urllib2.urlopen(url)
10
    html = urlHandler.read()
11
    print "'%s\' fetched in %ss" % (url, (time.time() - start))
12
13
def start_thread(url):
14
    thread = threading.Thread(target=fetch_url, args=(url,))
15-
    threads.append(thread)
15+
16
    return thread
17
18
threads = [start_thread(url) for url in urls]
19
for thread in threads:
20
    thread.join()
21
22
print "Elapsed Time: %s" % (time.time() - start)