nesting context managers

Ethan Furman ethan at stoneleaf.us
Tue Dec 20 13:02:35 EST 2011


Rami Chowdhury wrote:
> On Tue, Dec 20, 2011 at 16:56, Ulrich Eckhardt
> <ulrich.eckhardt at dominolaser.com> wrote:
>> To be extra safe or in more complicated scenarios, I could wrap this in a
>> try-except and explicitly close those that were already created, but
>> normally I'd expect the garbage collector to do that for me ... or am I then
>> implicitly assuming a specific implementation?
> 
> I'm no expert but I believe the basic garbage collection behavior is
> part of the language, and it's only details of breaking cycles that
> are specific to CPython -- can anyone correct me if I'm wrong?

Garbage collection is part of the language, but how, and when, is 
implementation specific.

Resource management (beyond basic memory allocation) should be handled 
directly.  Python 3 encourages this by complaining if there were still 
open files when it shuts down.

~Ethan~



More information about the Python-list mailing list