Message2589

Author leouserz
Recipients
Date 2007-01-12.16:08:30
SpamBayes Score
Marked as misclassified
Message-id
In-reply-to
Content
__del__ does not appear to work correctly if acquired in jython.  This py script works fine on Python 2.5:


class z:
   pass

a = z()
def __del__(a):
    print "DEL"
z.__del__ = __del__
a = None

x = z()
x = None

print dir(z)

class z:
    def __del__(a):
        print "DEL2"
f = z()
f = None

import sys
if(len(sys.argv) > 1):
    import java
    java.lang.System.gc()
    java.lang.Thread.sleep(5000)


z always has its __del__ called even if acquired.  In jython this appears not to work for classes that acquire __del__.  Im not sure of the cause, but I would expect the instance created after acquiring __del__ to fire "DEL" off.  I believe the problem for the second case is because PyClass does not mutate when __del__ is added to it.  Well it mutates but it doesn't appear to reset an internal variable that determines if the new PyInstance will be finalizable or not.  Additionally it appears that PyType defines a variable that is not used: "needs_finalizable".  PyClass looks for __del__ being set not "needs_finalizable".

Now for existing classes this poses a problem.  If __del__ is defined at instantiation time it is a PyFinalizableInstance that is created.  The documentation states that PyFinalizableInstance exists because of performance problems.  It would be good to see what these are.  The only solution I can think of at this moment is to remove PyFinalizableInstance and just make PyInstance with a finalize method.  It could then check on finalize if __del__ exists and do its work.


History
Date User Action Args
2008-02-20 17:18:37adminlinkissue1634167 messages
2008-02-20 17:18:37admincreate