Created
September 8, 2017 09:02
-
-
Save strizhechenko/e72120e43966ed7d007c84d568cc6e67 to your computer and use it in GitHub Desktop.
Send a lot of http(s) requests in testing purpose
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
| import sys | |
| import argparse | |
| from subprocess import Popen, PIPE | |
| import multiprocessing | |
| def curl(_): | |
| p = Popen(['curl', '-vkL', args.url], stdout=PIPE, stderr=PIPE) | |
| stdout, stderr = p.communicate() | |
| print "+" | |
| if args.quiet and p.returncode != 0: | |
| return | |
| print stderr | |
| def parse_args(): | |
| parser = argparse.ArgumentParser() | |
| parser.add_argument('-u', '--url', type=str) | |
| parser.add_argument('-t', '--threads', type=int, default=8) | |
| parser.add_argument('-c', '--count', type=int, default=1000) | |
| parser.add_argument('-q', '--quiet', action='store_true', default=False) | |
| return parser.parse_args() | |
| def main(): | |
| pool = multiprocessing.Pool(args.threads) | |
| pool.map(curl, range(args.count)) | |
| pool.close() | |
| if __name__ == '__main__': | |
| args = parse_args() | |
| main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment