开发者

Boost.Python: Weak reference to object?

开发者 https://www.devze.com 2023-03-23 23:25 出处:网络
Is there a way to get a weak reference to a Python object? With boost::python::object you get a strong/shared reference so as long as either C++ or Python holds a refe开发者_StackOverflow社区rence to

Is there a way to get a weak reference to a Python object? With boost::python::object you get a strong/shared reference so as long as either C++ or Python holds a refe开发者_StackOverflow社区rence to that object, it will not get deleted. I want only Python to hold a strong reference to an object, and C++ a weak one. Is that possible?


You need to go into the CPython API for that. Use PyWeakReference type from weakrefobject.h. The header exposes an API that's similar to weakref module — see the docs.

0

精彩评论

暂无评论...
验证码 换一张
取 消