Re: [C++-sig] Boost.Python: Callbacks to class functions

2011-08-01 Thread Paul-Cristian Manta
On Tue, Aug 2, 2011 at 8:24 AM, Jim Bosch wrote: > > Hmm. That might mean you need to do a big design change; while it often > works, one really isn't supposed to rely on __del__ being called when a > Python object first could be garbage-collected - when cycles are involved, > Python doesn't eve

Re: [C++-sig] Boost.Python: Callbacks to class functions

2011-08-01 Thread Jim Bosch
On 08/01/2011 09:44 PM, diego_pmc wrote: Are these cycles actually a problem in practice? Python does do garbage collection, so it might be that it knows about all these dependencies and just hasn't bothered to try to delete them because it doesn't need the memory yet. Y

Re: [C++-sig] Boost.Python: Callbacks to class functions

2011-08-01 Thread diego_pmc
On Tue, Aug 2, 2011 at 3:00 AM, Nat Goodspeed wrote: > > > http://docs.python.org/library/weakref.html#module-weakref > > Unfortunately, I can't use `weakref` I already tried that, but the problem is that the weak references get deleted (and their value set to `None`) before `__del__` is called. S

Re: [C++-sig] Boost.Python: Callbacks to class functions

2011-08-01 Thread Jim Bosch
On 08/01/2011 07:50 AM, diego_pmc wrote: I have an `EventManager` class written in C++ and exposed to Python. This is how I intended for it to be used from the Python side: class Something: def __init__(self): EventManager.addEventHandler(FooEvent, self.onFooEvent)

Re: [C++-sig] Boost.Python: Callbacks to class functions

2011-08-01 Thread Nat Goodspeed
On Aug 1, 2011, at 10:50 AM, diego_pmc wrote: > How should I capture Python function objects such > that I won't increase their reference count? I only need a weak reference to > the objects. http://docs.python.org/library/weakref.html#module-weakref I don't know how to access a Python weakref

[C++-sig] Boost.Python: Callbacks to class functions

2011-08-01 Thread diego_pmc
I have an `EventManager` class written in C++ and exposed to Python. This is how I intended for it to be used from the Python side: class Something: def __init__(self): EventManager.addEventHandler(FooEvent, self.onFooEvent) def __del__(self): EventManag