◐ Shell
clean mode source ↗

Message 353426 - Python tracker

I think the problem with your logic is that the weakref to F is part of the garbage set.  So, handle_finalizers() should detect that and clear the finalizer rather than call it.  Once we get to delete_garbage() and start calling tp_clear(), we can't be running weakref callbacks or finalizers.  The GC logic goes through great pains to ensure that.