import gc, os, sys, _testcapi # Disable the GC to avoid crash on GC collection gc.disable() obj = _testcapi.pyobject_freed() error = (_testcapi.pyobject_is_freed(obj) == False) # Exit immediately to avoid a crash while deallocating # the invalid object os._exit(int(error))