Hi,
I run across this problem, and couldn't find any solution (python 2.2.2)
:
Code :
===========
from __future__ import generators
[color=blue][color=green][color=darkred]
>>> class titi:[/color][/color][/color]
def __init__(self):
print "init"
def __del__(self):
print "del"
def Gen(self):
yield 1
[color=blue][color=green][color=darkred]
>>> c = titi()[/color][/color][/color]
init[color=blue][color=green][color=darkred]
>>> c = [][/color][/color][/color]
del
==============
Here, everything is normal...
But creating a generator :
Code :
===========
[color=blue][color=green][color=darkred]
>>> class toto:[/color][/color][/color]
def __init__(self):
print "init"
self.Coroutine = self.Gen()
def __del__(self):
print "del"
def Gen(self):
yield 1
[color=blue][color=green][color=darkred]
>>> a = toto()[/color][/color][/color]
init[color=blue][color=green][color=darkred]
>>> c = [][/color][/color][/color]
<--- 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
I run across this problem, and couldn't find any solution (python 2.2.2)
:
Code :
===========
from __future__ import generators
[color=blue][color=green][color=darkred]
>>> class titi:[/color][/color][/color]
def __init__(self):
print "init"
def __del__(self):
print "del"
def Gen(self):
yield 1
[color=blue][color=green][color=darkred]
>>> c = titi()[/color][/color][/color]
init[color=blue][color=green][color=darkred]
>>> c = [][/color][/color][/color]
del
==============
Here, everything is normal...
But creating a generator :
Code :
===========
[color=blue][color=green][color=darkred]
>>> class toto:[/color][/color][/color]
def __init__(self):
print "init"
self.Coroutine = self.Gen()
def __del__(self):
print "del"
def Gen(self):
yield 1
[color=blue][color=green][color=darkred]
>>> a = toto()[/color][/color][/color]
init[color=blue][color=green][color=darkred]
>>> c = [][/color][/color][/color]
<--- 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
Comment