teempe

sdfsdfsdfsfsdfsdfsfssdfsdfsdfsdf

Mar 8th, 2018
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.59 KB | None | 0 0
  1. #python2.5
  2. import threading
  3. import urllib2
  4. import time
  5.  
  6. start = time.time()
  7. urls = ["http://www.google.com", "http://www.apple.com", "http://www.microsoft.com",
  8.         "http://www.amazon.com", "http://www.facebook.com"]
  9.  
  10. def fetch_url(url):
  11.     urlHandler = urllib2.urlopen(url)
  12.     html = urlHandler.read()
  13.     print "'%s\' fetched in %ss" % (url, (time.time() - start))
  14.  
  15. threads = [threading.Thread(target=fetch_url, args=(url,)) for url in urls]
  16. for thread in threads:
  17.     thread.start()
  18. for thread in threads:
  19.     thread.join()
  20.  
  21. print "Elapsed Time: %s" % (time.time() - start)
Advertisement
Add Comment
Please, Sign In to add comment