Skip to content

Instantly share code, notes, and snippets.

@amrakm
Created July 1, 2022 13:16
Show Gist options
  • Save amrakm/7b40c3820f35b0bf02e2d811c32ccb3b to your computer and use it in GitHub Desktop.
Save amrakm/7b40c3820f35b0bf02e2d811c32ccb3b to your computer and use it in GitHub Desktop.
download url parallel
import eventlet,sys
# note: this urllib import doesn't work in Python2
from eventlet.green.urllib.request import urlopen
file = sys.argv[1] # list of urls
with open(file,'r') as f:
urls = [x.rstrip() for x in f.readlines()]
urls = urls + urls
urls = urls + urls
urls = urls + urls
def fetch(url):
try:
return urlopen(url).read()
except:
return [1]
pool = eventlet.GreenPool(8)
for body in pool.imap(fetch, urls):
print(f"got body {len(body)}")
print(len(urls))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment