[mod_python] Destructors called more than Constructors

S.R.Pardá linux at qbox.es
Sun Jun 4 12:25:45 EDT 2006


Hi,

I'm having an unexpected behavior in destructor calls.

I have 1 class with class attributtes counting destructions and
constructions.

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):
		...
		self.c = C()
		...

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

   def __init__(self):
	...
	constcount += 1
	...

   def __del__(self):
	...
	destrcount -= 1
	...

--------------------------------------------------------



Thank You

	S.R.Pardá




More information about the Mod_python mailing list