简体   繁体   中英

Boost.Python: Getting a python weak reference to a wrapped C++ object

I've wrapped a C++ class using Boost.Python. These Objects have strong references (boost::shared_ptr) on the C++-side, and there may be intermittent strong references in Python as well. So far, everything works well. However, if I create a python weak reference from one of the strong references, this weak reference is deleted as soon as the last python strong reference disappears. I'd like the weak reference to stay alive until the last strong reference on the C++ side disappears as well. Is it possible to achieve that?

Phrased another way: Is there a way to find out from python if a particular C++ object (wrapped by Boost.Python) still exists?

How are you holding a "C++ strong reference" to the wrapped class ?

I'm quite rusty on boost python, but I believe it's the boost::shared_ptr's deleter presence which ensures lifetime management.

If that isn't the problem, you probably need to hold the instance in C++ in a boost::python::object.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM