Advertisement
rfmonk

parallel.py

Jan 6th, 2014
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.45 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3.  
  4. import urllib2
  5. from multiprocessing.dummy import Pool as ThreadPool
  6.  
  7. urls = [
  8.     'https://medium.com/p/40e9b2b36148'
  9.     # Thanks for the awesome tut in parallelism
  10.     # follow the link above for full tut
  11. ]
  12.  
  13. # Make the Pool of workers
  14. pool = ThreadPool(4)
  15.  
  16. # Open the urls in their own threads
  17. # and return the results
  18. results = pool.map(urllib2.urlopen, urls)
  19.  
  20. # Close the pool and wait for the work to finish
  21. pool.close()
  22. pool.join()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement