def METHOD_NAME(cls):
    # At shutdown invoke finalizers for which atexit is true.
    # This is called once all other non-daemonic threads have been
    # joined.
    reenable_gc = False
    try:
        if cls._registry:
            import gc
            if gc.isenabled():
                reenable_gc = True
                gc.disable()
            pending = None
            while True:
                if pending is None or weakref_finalize._dirty:
                    pending = cls._select_for_exit()
                    weakref_finalize._dirty = False
                if not pending:
                    break
                f = pending.pop()
                try:
                    # gc is disabled, so (assuming no daemonic
                    # threads) the following is the only line in
                    # this function which might trigger creation
                    # of a new finalizer
                    f()
                except Exception:
                    sys.excepthook(*sys.exc_info())
                assert f not in cls._registry
    finally:
        # prevent any more finalizers from executing during shutdown
        weakref_finalize._shutdown = True
        if reenable_gc:
            gc.enable()