import gc import threading class RefCycle: def __init__(self): self.cycle = self def __del__(self): print("GC in thread", threading.current_thread()) print("main thread is", threading.main_thread()) print("-- before shutdown --") RefCycle() gc.collect() print("-- during shutdown --") x = RefCycle()