Created
April 14, 2019 15:29
-
-
Save saurabh-hirani/f01bd7ecf3b21525f43aed888fd089a8 to your computer and use it in GitHub Desktop.
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
| #!/usr/bin/env python | |
| from __future__ import print_function | |
| import gevent_openssl | |
| gevent_openssl.monkey_patch() | |
| import grequests | |
| import logging | |
| import urllib3 | |
| urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning) | |
| def setup_logging(): | |
| logger = logging.getLogger() | |
| logger.setLevel(logging.DEBUG) | |
| logging_format = '%(asctime)s %(message)s' | |
| formatter = logging.Formatter(logging_format) | |
| logHandler = logging.StreamHandler() | |
| logHandler.setFormatter(formatter) | |
| logger.addHandler(logHandler) | |
| return logger | |
| def make_requests(url, url_count): | |
| pending_requests = [] | |
| for i in range(url_count): | |
| pending_requests.append(grequests.get(url, params={'page': i}, verify=False)) | |
| all_responses = grequests.map(pending_requests) | |
| print(all_responses) | |
| def main(): | |
| logger = setup_logging() | |
| logger.info('START') | |
| make_requests('https://localhost:8082/delay/1', 10) | |
| logger.info('END') | |
| if __name__ == '__main__': | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment