Skip to content

Instantly share code, notes, and snippets.

@henriquebastos
Created May 5, 2022 18:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save henriquebastos/d64dd3d1b27ed9fc3c6c9ab1c656e4ea to your computer and use it in GitHub Desktop.
Save henriquebastos/d64dd3d1b27ed9fc3c6c9ab1c656e4ea to your computer and use it in GitHub Desktop.
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