Created
May 5, 2022 18:12
-
-
Save henriquebastos/d64dd3d1b27ed9fc3c6c9ab1c656e4ea to your computer and use it in GitHub Desktop.
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 requests_futures.sessions import FuturesSession | |
def response_for_urls(urls): | |
"""Asynchronously get response for many urls.""" | |
with FuturesSession() as session: | |
futures = [ | |
session.get(url) for url in urls | |
] | |
return (f.result() for f in futures) | |
if __name__ == "__main__": | |
urls = [ | |
'https://www.google.com', | |
'https://www.discourse.org', | |
'https://www.stackoverflow.com', | |
'https://www.henriquebastos.net', | |
] | |
print(list(response_for_urls(urls))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment