You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
weakref.finalize documentation refers to old interpreter shutdown behavior #69524
"A finalizer will never invoke its callback during the later part of the interpreter shutdown when module globals are liable to have been replaced by None."
While it may not invoke its callback during shutdown (I don't know if it does, or if it should), as of Python 3.4 (which is when weakref.finalize was introduced), module globals aren't set to None anymore, right? https://docs.python.org/3/whatsnew/3.4.html#whatsnew-pep-442
Presumably the docs should be updated not to mention a behavior that no longer occurs (and if it will or should be invoked, weakref.finalizer should have documentation or code updated).
Adding @pitrou to the nosylist as he implemented PEP-442 in bpo-18112. If he agrees with the proposed change, then I believe this can be marked as 'easy'.
This statement is still correct. weakref.finalize callbacks are called from an atexit hook and are not called after it. Later in the shutdown, the globals of modules that are still alive can still be replaced by None. The outdated statement in the "Comparing finalizers with __del__() methods" section is fixed in #162769 (gh-64352).
Activity
MojoVampire commentedon Oct 8, 2015
In weakref.finalize's documentation ( https://docs.python.org/3/library/weakref.html#weakref.finalize ), it says:
"A finalizer will never invoke its callback during the later part of the interpreter shutdown when module globals are liable to have been replaced by None."
While it may not invoke its callback during shutdown (I don't know if it does, or if it should), as of Python 3.4 (which is when weakref.finalize was introduced), module globals aren't set to None anymore, right? https://docs.python.org/3/whatsnew/3.4.html#whatsnew-pep-442
Presumably the docs should be updated not to mention a behavior that no longer occurs (and if it will or should be invoked, weakref.finalizer should have documentation or code updated).
csabella commentedon Feb 25, 2019
Adding @pitrou to the nosylist as he implemented PEP-442 in bpo-18112. If he agrees with the proposed change, then I believe this can be marked as 'easy'.
serhiy-storchaka commentedon Nov 27, 2026
This statement is still correct.
weakref.finalizecallbacks are called from anatexithook and are not called after it. Later in the shutdown, the globals of modules that are still alive can still be replaced byNone. The outdated statement in the "Comparing finalizers with__del__()methods" section is fixed in #162769 (gh-64352).