[mod_python] destructor againsts constructor calls

S.R.Pardá linux at qbox.es
Sun Jun 4 13:14:42 EDT 2006

Sorry to repeat:
I want to note that in module f: I'm using a session to save last state.

I'm having an unexpected behavior in destructor calls.

I have 1 class with class attributtes counting destructions and

When I reload modules c.py (defining DEBUG as True) all works Ok.

If I don't reload (DEBUG as False), destructor is called more times 3
times for 2 constructors calls.

I don't understand why the different behavior.

--- index.psp ----------------------------------------
DEBUG = False # or TRUE 

from c import C
if DEBUG: reload C
from f import F
if DEBUG: reload F

f = F()
c = f.c

req.write ('Constructed %s' % C.constcount)
req.write (' Destructed %s' % C.destrcount)

--- f.py --------------------------------------------
from c import C
if DEBUG: reload C

class F:
        def __init__(self):
		if session.has_key('cstate'): 
			self.c = session('cstate')
			self.c = C()
		session('cstate') = self.c

--- c.py ---------------------------------------------
class C:
   constcount = 0
   destrcount = 0

   def __init__(self):
        constcount += 1

   def __del__(self):
        destrcount -= 1


Thank You


More information about the Mod_python mailing list