Skip to content

Instantly share code, notes, and snippets.

@0xBADCA7
Created August 27, 2016 06:23
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 0xBADCA7/f95a3aae3b7507a61794d31cad3c3b66 to your computer and use it in GitHub Desktop.
Save 0xBADCA7/f95a3aae3b7507a61794d31cad3c3b66 to your computer and use it in GitHub Desktop.
Async HTTP requests in Python
from concurrent.futures import ThreadPoolExecutor
from requests_futures.sessions import FuturesSession
def outp(response):
print(response)
print(response.headers)
print(response.text)
urls = [
"https://www.google.com",
"http://github.com",
"http://www.microsoft.com"
]
responses = []
session = FuturesSession(executor=ThreadPoolExecutor(max_workers=10))
for url in urls:
future = session.get(url)
response = future.result()
responses.append(response)
id = 0
for response in responses:
id += 1
print(u"{}: {}\r\n".format(id, response.content))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment