Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import threading
- import urllib2
- import time
- start = time.time()
- urls = ["http://www.google.com", "http://www.apple.com", "http://www.microsoft.com", "http://www.amazon.com", "http://www.facebook.com"]
- def fetch_url(url):
- urlHandler = urllib2.urlopen(url)
- html = urlHandler.read()
- print "'%s\' fetched in %ss" % (url, (time.time() - start))
- def start_thread(url):
- thread = threading.Thread(target=fetch_url, args=(url,))
- thread.start()
- return thread
- threads = [start_thread(url) for url in urls]
- for thread in threads:
- thread.join()
- print "Elapsed Time: %s" % (time.time() - start)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement