Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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