我正在将一些 weakrefs 从 Python 传递到 C++ 类,但是 C++ 析构函数在真实对象已经死亡时积极尝试访问 ref,显然它崩溃了......
是否有任何 Python C/API 方法来查明 Python 引用是否仍然存在或任何其他已知的解决方法?
谢谢
最佳答案
来自 Python C API文档:
PyObject* PyWeakref_GetObject(PyObject *ref)
Return value: Borrowed reference.
Return the referenced object from a weak reference, ref. If the referent is no longer live, returns None. New in version 2.2.
关于c++ - Python - 如何检查弱引用是否仍然可用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2993393/