问题描述
我遇到了这个问题,并且找不到任何解决方案(python 2.2.2)
:
代码:
===========
来自__future__导入生成器的
< ---没有什么!!!
==============
我无法理解为什么在创建生成器时没有调用析构函数,以及我应该怎样做才能得到正确的结果。行为。
(也许我错过了一些明显的东西,但我找不到它)
感谢您的帮助,
Emmanuel
你的意思是' 'c = toto()''?
< ---没有什么!!! /> ==============
我无法理解为什么在创建生成器时不会调用析构函数,我应该怎么做做一个正确的做法行为。
要么不创建参考循环,要么用del c.Coroutine打破它。
Terry J. Reedy
首先,a仍在引用你的toto对象。我想你
的意思是a = []这里。但即使你做了a = [],析构函数
仍然没有被调用。必须仍然有对该对象的引用。我的b $ b猜测是生成器(直接或间接)引用了
对象,创建了一个自引用循环。
考虑以下仅仅引用函数的修改,
并且不创建生成器:
-Mark
Python有垃圾收集器将尝试使用
循环引用来查找这些对象。
来自test import *
我检查了文档那个gc.garbage列表并且它说
如果cyles具有带有__del__方法的
对象,则收集器不能在周期中释放对象。所以它把它们放在这个列表中。
我想知道其他垃圾收集者在这种情况下做了什么?有人
知道吗? Java?
Rob
Hi,
I run across this problem, and couldn''t find any solution (python 2.2.2)
:
Code :
===========
from __future__ import generators
<--- 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
did you mean ''c = toto()''?
<--- 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.
Either do not create reference loop or break it with del c.Coroutine.
Terry J. Reedy
First of all, "a" is still referencing your toto object. I think you
meant "a = []" here. But even if you did "a = []", the destructor
still isn''t called. There must still be a reference to the object. My
guess is that the generator (directly or indirectly) is referencing the
object, creating a self referential loop.
Consider the following modification that merely references a function,
and does not create a generator:
-Mark
Python has a garbage collector that will try to find these objects with
cyclic references.
from test import *
I checked out the documentation for that gc.garbage list and it says
that the collector can''t free objects in cycles if the cyles have
objects that have __del__ methods. So it puts them in this list.
I wonder what other garbage collectors do in this situation? Anyone
know? Java?
Rob
这篇关于一个类内的生成器阻止__del__ ??的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!