I have C ++ code that passes events to Python objects. Observers are stored as weak_ptr s, so they donβt need to unregister.
This works in C ++, but the weak pointer bridges and weak Python links are unpleasant (I also want Python event handlers not to be supported by subscriptions the same as in C ++ code). In order to have a living observer, something must have a common pointer to it while the object is alive, so it comes down to the fact that the observer on the Python earth controls the lifetime of the C ++ observer object.
The approaches I came to so far include a significant number of template and intermediate objects (e.g., creating another PyTypeObject for a type that stores a C ++ observer and a weak reference to the Python observer and sets it as a member of the Python observer, so it dies with him).
The question is, is there an obvious way to do this?
source share