Generator inside a class prevent __del__ ??

Emmanuel eastier at free.fr
Tue Apr 20 20:04:38 EDT 2004


Hi,

I run across this problem, and couldn't find any solution (python 2.2.2)
:

Code :
===========
from __future__ import generators

>>> class titi:
            def __init__(self):
                print "init"
            def __del__(self):
                print "del"
            def Gen(self):
                yield 1

>>> c = titi()
init
>>> c = []
del
==============
Here, everything is normal...
But creating a generator :

Code :
===========

>>> class toto:
            def __init__(self):
                print "init"
                self.Coroutine = self.Gen()
            def __del__(self):
                print "del"
            def Gen(self):
                yield 1

>>> a = toto()
init
>>> c = []
                <--- Nothing there !!!
==============

I can't understand why the destructor is not called when a generator is
created, and what I should do to have a "correct" behavior.
(perhaps I missed something obvious, but I can't find it )
Thank you for any help,

Emmanuel







More information about the Python-list mailing list