Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Test how many threads we can run at once
"""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
You can’t perform that action at this time.