import os, threading from concurrent.futures import ThreadPoolExecutor def get_vm_size(): for line in open("/proc/{0}/status".format(os.getpid())): if line.startswith("VmSize:"): return line.split()[1] else: return "unknown" TASKS = WORKERS = 100 executor = ThreadPoolExecutor(max_workers=WORKERS) for x in range(TASKS): print("Submitting {0}, VM Size {1}, {2} threads".format(x, get_vm_size(), len(threading.enumerate()))) executor.submit(lambda t: t, x).result()