max_threads_test.py 795 Bytes
import threading
import time
import os
import sys

def main():
    print(f"Logical CPUs: {os.cpu_count()}")
    print(f"Python version: {sys.version}")
    print("Testing maximum number of threads...")
    threads = []
    max_threads = 0
    try:
        while True:
            t = threading.Thread(target=time.sleep, args=(10,))
            t.start()
            threads.append(t)
            max_threads += 1
            if max_threads % 100 == 0:
                print(f"Threads started: {max_threads}")
    except Exception as e:
        print(f"Max threads reached: {max_threads}")
        print(f"Exception: {e}")
    finally:
        print("Cleaning up threads...")
        for t in threads:
            t.join(timeout=0.1)
        print("Done.")

if __name__ == "__main__":
    main()