Destruction of generator objects
Stefan Bellon
sbellon at sbellon.de
Sat Aug 11 10:04:49 EDT 2007
On Sat, 11 Aug, Marc 'BlackJack' Rintsch wrote:
> On Sat, 11 Aug 2007 14:50:33 +0200, Stefan Bellon wrote:
> > But then, even when terminating the interpreter, __del__ is not
> > called.
>
> Because that is not guaranteed by the language reference. The reason
> why it is a bad idea to depend on `__del__` for important resource
> management.
Ok, but then we are back to my initial question of whether the destroy
of
def get_data(obj):
iter = make_iter(obj)
while more(iter):
yield next(iter)
destroy(iter)
can be guaranteed somehow in Python 2.4 while it can be done in Python
2.5 like follows:
def get_data(obj):
iter = make_iter(obj)
try:
while more(iter):
yield next(iter)
finally:
destroy(iter)
And then the answer is: no, it cannot be done in 2.4 (like Alex
Martelli already said ;-)
--
Stefan Bellon
More information about the Python-list
mailing list