Skip to content

Instantly share code, notes, and snippets.

@ableasdale
Created July 12, 2016 15:55
Show Gist options
  • Save ableasdale/9cb7888dcf269db981ac50c9307eb0ae to your computer and use it in GitHub Desktop.
Save ableasdale/9cb7888dcf269db981ac50c9307eb0ae to your computer and use it in GitHub Desktop.
Python: using httplib2 and ThreadPoolExecutor to create a large number of concurrent HTTP requests
import httplib2
import concurrent.futures
EMPTY_REQ_BODY = body = ""
URI = "http://0.0.0.0:8001/admin/v1/timestamp"
REQ_HEADERS = headers = {'Accept': 'text/plain'}
EXECUTOR = concurrent.futures.ThreadPoolExecutor(max_workers=64)
def print_http_response(num):
h = httplib2.Http()
h.add_credentials('q', 'q')
response_header, response_body = h.request(URI, "GET", EMPTY_REQ_BODY, REQ_HEADERS)
print(num, response_header.status, response_body)
for i in range(1000):
EXECUTOR.submit(print_http_response, i)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment