Closing generators

Thomas Rachel nutznetz-0c1b6768-bfa9-48d5-a470-7603bd3aa915 at spamschutz.glglgl.de
Fri Apr 22 04:01:13 EDT 2011


Am 22.04.2011 09:01, schrieb Wolfgang Rohdewald:

> On Freitag 22 April 2011, Terry Reedy wrote:

>> When returning from the function, g, if local, should
>> disappear.
>
> yes - it disappears in the sense that it no longer
> accessible, but
>
> AFAIK python makes no guarantees as for when an object
> is destroyed - CPython counts references and destroys
> when no reference is left, but that is implementation
> specific

Right - that's what I am thought about when writing the OP. But Terry is 
right - often the generator doesn't need to know that is 
closed/terminated, which is anyway possible only since 2.5.

But in these (admittedly rarely) cases, it is better practice to close 
explicitly, isn't it?


Unsure,
Thomas



More information about the Python-list mailing list