Using Boost.Python, is there a way to call a Python function that’s been passed through a weakref? The following code doesn’t work:
import weakref
def foo():
print 'it works'
def func():
return weakref.ref(foo)
The following is the C++:
object module = import("test");
object func(module.attr("func"));
object foo = func();
foo(); // Should print 'it works', but it prints nothing
However, if I pass the function object without weakref, it all works fine. Is there any way to make this work?
From weakref documentation:
So, given your snippet: