Pablo Galindo Salgado <pablog...@gmail.com> added the comment:
One thing we could do is call the weakref callbacks *after* we call `finalize_garbage` and only on the "final_unreachable" set (the objects that do not resurrect). Notice that doing this still has one difference: the callback will be executed AFTER the finalizer while in the normal refcount path is executed BEFORE the finalizer. I have not given enough thought to the correctness of doing this but my gut feeling tells me something can go wrong if we do that. What do you think about this path, Tim? Here is the diff I am refering to for clarity: diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 5727820f09..498ff927ab 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -1252,9 +1252,6 @@ collect(PyThreadState *tstate, int generation, } } - /* Clear weakrefs and invoke callbacks as necessary. */ - m += handle_weakrefs(&unreachable, old); - validate_list(old, collecting_clear_unreachable_clear); validate_list(&unreachable, collecting_set_unreachable_clear); @@ -1267,6 +1264,9 @@ collect(PyThreadState *tstate, int generation, PyGC_Head final_unreachable; handle_resurrected_objects(&unreachable, &final_unreachable, old); + /* Clear weakrefs and invoke callbacks as necessary. */ + m += handle_weakrefs(&final_unreachable, old); + /* Call tp_clear on objects in the final_unreachable set. This will cause * the reference cycles to be broken. It may also cause some objects * in finalizers to be freed. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue40312> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com