Skip to content

Instantly share code, notes, and snippets.

@omerasif57
Last active February 10, 2021 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omerasif57/20c99d20b88b5794ce21b62478aba48f to your computer and use it in GitHub Desktop.
Save omerasif57/20c99d20b88b5794ce21b62478aba48f to your computer and use it in GitHub Desktop.
Lorempicsum photo downloads using multi threads
from multiprocessing.pool import ThreadPool
from time import time
import wget
urlp = "https://picsum.photos/id/{}/720/1200"
urls = [(urlp.format(x), "{}.jpg".format(x)) for x in range(10)]
def url_response(url):
print("downloading {} to {}".format(url[0], url[1]))
url, path = url
wget.download(url, path)
start = time()
results = ThreadPool(5).imap_unordered(url_response, urls)
for r in results:
print(r)
print(f"Time to download: {time() - start}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment