[C++-sig] C++ chain method works unexpectedly in Python
charlessolar at gmail.com
Mon Apr 18 02:56:45 CEST 2011
I have a python module written in C++, and the C++ code has a few instances
that involve method chaining. I was experimenting with python support for
these methods and I found something odd.
However it seems this is more a python eccentricity than Boost Python,
consider the following code sample.
def __init__( self ):
def __del__( self ):
def foo( self ):
def bar( self ):
And some sample uses:
<__main__.Test instance at 0x2aef40e33998>
Note that __del__ was never called, the object still exists somewhere..
There is another odd thing though, if I repeat the same line, the previous
version gets destroyed and replaced by the new version, but only after the
chain methods are done, eg:
Del <-- Old one, NOT the current instance
<__main__.Test instance at 0x2b72bc78d998>
However if I do:
# To make sure del is not called by the function returning
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 4, in Tester
That time __del__ was called immediately ( as intended ).
Is there something I should be aware of here? Some sort of difference
between the global instances and ones defined in a function? Can I do
anything so global instances are cleaned up immediately like they are inside
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Cplusplus-sig