Created
November 3, 2016 13:53
-
-
Save benhoyt/c35aaa46935bda0180ce9a2b75a4db0d to your computer and use it in GitHub Desktop.
Test how many threads we can run at once
This file contains 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
"""Test how many threads we can run at once.""" | |
import itertools | |
import threading | |
import time | |
import sys | |
import requests | |
successes = itertools.count() | |
failures = itertools.count() | |
def thread_func(): | |
while True: | |
time.sleep(0.5) | |
try: | |
requests.get('http://www.example.com').text | |
next(successes) | |
except: | |
next(failures) | |
def main(n): | |
threading.stack_size(64 * 1024) | |
for i in range(n): | |
thread = threading.Thread(target=thread_func) | |
thread.start() | |
time.sleep(0.005) | |
n = 0 | |
while True: | |
time.sleep(1) | |
print(next(successes) - n, next(failures) - n) | |
n += 1 | |
if __name__ == '__main__': | |
main(int(sys.argv[1])) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment