It is __del__ calling twice for some instances?

Max Yuzhakov gmt at sdf-eu.org
Wed Aug 16 14:22:05 EDT 2006


Hello!

It is correct behaviour for python to call __del__ on some
identity of a class object more than once?

In brief I shall describe a situation. Sorry for my english.

For debugin purposes I'm put in my module global counters
for counting __init__ and __del__ calls.

This is a sample code for clearness:
-------------------------------------------------------
init_cnt = 0
del_cnt = 0

class foo:
    def __init__(self):
        global init_cnt
        init_cnt += 1

    def __del__(self):
        global del_cnt
        del_cnt += 1

def stat():
    print "init_cnt = %d" % init_cnt
    print "del_cnt = %d" % del_cnt
    print "difference = %d" % init_cnt-del_cnt
-------------------------------------------------------
And the result of a stat() call in some moment of time
looks like so:

init_cnt = 6233
del_cnt = 6234
difference = -1

It is __del__ called twice for some instance?

Thanks in advance!
-- 
GMT More Then ...



More information about the Python-list mailing list