#! /usr/bin/env python import gc import sys import time import threading import subprocess def main(): assert gc.isenabled() try: sys.setswitchinterval(0.00001) except AttributeError: sys.setcheckinterval(0) while gc.isenabled(): print("Starting threads...") stop_event = threading.Event() threads = [] for x in range(64): thread = threading.Thread(target=thread_body, args=(stop_event,)) thread.start() threads.append(thread) time.sleep(10) print("Stopping threads...") stop_event.set() for thread in threads: thread.join() print("GC:", gc.isenabled()) time.sleep(2) def thread_body(stop_event): while not stop_event.is_set(): subprocess.Popen(["true"]) if __name__ == "__main__": main()