This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author vstinner
Recipients Mark.Shannon, christian.heimes, jdemeyer, lukasz.langa, petr.viktorin, vstinner
Date 2019-09-02.11:27:53
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
(gdb) print ((PyFunctionObject*)func).func_qualname 
$29 = 'WeakValueDictionary.__init__.<locals>.remove'

This is a temporary remove() function declared in weakref.WeakValueDictionary constructor:

class WeakKeyDictionary(_collections_abc.MutableMapping):
    def __init__(self, dict=None):
        def remove(k, selfref=ref(self)):
        self._remove = remove

    def __setitem__(self, key, value):[ref(key, self._remove)] = value


Simplified gdb traceback:

-> PyImport_Cleanup()
-> _PyGC_CollectNoFail()
-> delete_garbage()
-> func_clear(op=0x7fffe6ebfd30) at /usr/src/debug/python3-3.8.0~b4-1.fc32.x86_64/Objects/funcobject.c:584
-> tupledealloc()
-> cell_dealloc()
-> dict_dealloc()
-> dictkeys_decref()
-> cfield_dealloc () from _cffi_backend
-> PyObject_ClearWeakRefs()
-> _PyFunction_Vectorcall (func=<function at remote 0x7fffe6ebfd30>, ...)

PyImport_Cleanup() calls delete_garbage() which calls func_clear(op=0x7fffe6ebfd30).

But while the function closure is destroyed, a cffi object stored in a dict (namespace?) (stored in the function closure) is cleared, and there was a weak reference to this cffi object with a callback... which is the cleared function (Python object 0x7fffe6ebfd30)...


I don't understand why/how remove() gets a closure. I modified to ensure that remove.__closure__ is None: test_weakref still pass.
Date User Action Args
2019-09-02 11:27:53vstinnersetrecipients: + vstinner, christian.heimes, petr.viktorin, lukasz.langa, Mark.Shannon, jdemeyer
2019-09-02 11:27:53vstinnersetmessageid: <>
2019-09-02 11:27:53vstinnerlinkissue38006 messages
2019-09-02 11:27:53vstinnercreate