Skip to content

Instantly share code, notes, and snippets.

@4sushi
Last active October 28, 2021 14:43
Show Gist options
  • Save 4sushi/93bfdd6e10a65ba63d076e92b9fe39ff to your computer and use it in GitHub Desktop.
Save 4sushi/93bfdd6e10a65ba63d076e92b9fe39ff to your computer and use it in GitHub Desktop.
import requests
from multiprocessing import Pool
import time
def get_url(url):
result = requests.get(url, params={})
return url
if __name__ == '__main__':
urls = ['https://www.google.com/', 'https://foursquare.com/', 'https://www.yahoo.com/', 'https://www.bing.com/', "https://www.yelp.com/"]
t = time.time()
with Pool(5) as p:
res= p.map(get_url, urls)
for url in res:
print(url)
print("Time with pool processing: {:.3}s".format(time.time() - t) )
t = time.time()
for url in urls:
result = get_url(url)
print(result)
print("Time sequential processing: {:.3}s".format(time.time() - t) )
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment