import threading import time exiting = False def spin(): while not exiting: time.sleep(0.000001) for i in range(0,500): threading.Thread(target=spin).start() try: spin() finally: exiting = True