Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #17600

Re: nesting context managers

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.chainon-marquant.org!news-transit.tcx.org.uk!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ethan@stoneleaf.us>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.003
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'cpython': 0.05; 'complaining': 0.07; 'python': 0.08; 'created,': 0.09; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'garbage': 0.09; 'message- id:@stoneleaf.us': 0.09; 'received:gator410.hostgator.com': 0.09; 'specific.': 0.09; '~ethan~': 0.09; 'eckhardt': 0.16; 'how,': 0.16; 'received:72.11': 0.16; 'received:72.11.125': 0.16; 'received:72.11.125.166': 0.16; 'language,': 0.17; 'wrote:': 0.18; 'wrap': 0.18; 'memory': 0.21; 'dec': 0.22; 'header:In-Reply-To:1': 0.22; 'wrong?': 0.23; "i'm": 0.26; 'expect': 0.26; 'assuming': 0.29; 'explicitly': 0.29; 'correct': 0.29; 'cycles': 0.30; 'implicitly': 0.30; 'anyone': 0.31; 'tue,': 0.32; 'header:User- Agent:1': 0.33; 'there': 0.33; 'to:addr:python-list': 0.34; 'handled': 0.34; 'normally': 0.34; '...': 0.36; 'but': 0.37; 'could': 0.37; 'open': 0.38; "i'd": 0.39; 'should': 0.39; 'files': 0.39; "it's": 0.40; 'to:addr:python.org': 0.40; 'management': 0.60; 'more': 0.61; '2011': 0.61; 'expert': 0.62; 'received:websitewelcome.com': 0.64; 'details': 0.65; 'believe': 0.65; 'encourages': 0.67; 'received:184': 0.67; 'received:69.93': 0.67; 'directly.': 0.68; 'collection': 0.69; 'safe': 0.70
Date Tue, 20 Dec 2011 10:02:35 -0800
From Ethan Furman <ethan@stoneleaf.us>
User-Agent Thunderbird 1.5.0.10 (Windows/20070221)
MIME-Version 1.0
To python-list@python.org
Subject Re: nesting context managers
References <ash6s8-qj5.ln1@satorlaser.homedns.org> <nbr6s8-n86.ln1@satorlaser.homedns.org> <CAGEKe-1HzmQZU9tYwtH6W1DyRoRiSwCmojqRhfJ1MBr5LxO-=w@mail.gmail.com>
In-Reply-To <CAGEKe-1HzmQZU9tYwtH6W1DyRoRiSwCmojqRhfJ1MBr5LxO-=w@mail.gmail.com>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
X-AntiAbuse This header was added to track abuse, please include it with any abuse report
X-AntiAbuse Primary Hostname - gator410.hostgator.com
X-AntiAbuse Original Domain - python.org
X-AntiAbuse Originator/Caller UID/GID - [47 12] / [47 12]
X-AntiAbuse Sender Address Domain - stoneleaf.us
X-BWhitelist no
X-Source
X-Source-Args
X-Source-Dir
X-Source-Sender mail.admailinc.com ([192.168.10.136]) [72.11.125.166]:3857
X-Source-Auth ethan+stoneleaf.us
X-Email-Count 3
X-Source-Cap dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ==
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.3874.1324407140.27778.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1324407140 news.xs4all.nl 6894 [2001:888:2000:d::a6]:33677
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:17600

Show key headers only | View raw


Rami Chowdhury wrote:
> On Tue, Dec 20, 2011 at 16:56, Ulrich Eckhardt
> <ulrich.eckhardt@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~

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

nesting context managers Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2011-12-20 15:15 +0100
  Re: nesting context managers Rami Chowdhury <rami.chowdhury@gmail.com> - 2011-12-20 16:25 +0000
  Re: nesting context managers Ulrich Eckhardt <ulrich.eckhardt@dominolaser.com> - 2011-12-20 17:56 +0100
    Re: nesting context managers Rami Chowdhury <rami.chowdhury@gmail.com> - 2011-12-20 17:46 +0000
    Re: nesting context managers Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-20 11:46 -0700
    Re: nesting context managers Ethan Furman <ethan@stoneleaf.us> - 2011-12-20 10:02 -0800
    Re: nesting context managers Ian Kelly <ian.g.kelly@gmail.com> - 2011-12-20 11:55 -0700

csiph-web