Skip to content

Instantly share code, notes, and snippets.

@arajkumar
Created January 25, 2021 06:33
Show Gist options
  • Save arajkumar/d58ada4a9448396795496f7c46f39f70 to your computer and use it in GitHub Desktop.
Save arajkumar/d58ada4a9448396795496f7c46f39f70 to your computer and use it in GitHub Desktop.
test_requests_futures.py
# https://pypi.org/project/requests-futures/
from requests_futures.sessions import FuturesSession
from concurrent.futures import wait, ALL_COMPLETED
from time import time
concurrent_limit = 10
total_reqs = 10
each_request_duration = 5 # simulated delay
completion_timeout = 11
session = FuturesSession(max_workers=concurrent_limit)
reqs = []
start = time()
for i in range(0, total_reqs):
req = session.get(f'http://httpbin.org/delay/{each_request_duration}')
reqs.append(req)
ans = wait(reqs, timeout=completion_timeout, return_when=ALL_COMPLETED)
end = time()
print('done {}, not_done {}'.format(len(ans.done), len(ans.not_done)))
print('took {} sec'.format(end - start))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment