Created
January 25, 2021 06:33
-
-
Save arajkumar/d58ada4a9448396795496f7c46f39f70 to your computer and use it in GitHub Desktop.
test_requests_futures.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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