Last active
February 10, 2021 09:42
-
-
Save omerasif57/20c99d20b88b5794ce21b62478aba48f to your computer and use it in GitHub Desktop.
Lorempicsum photo downloads using multi threads
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
wget |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment