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


Groups > comp.lang.python > #18840

Re: contextlib.contextmanager and try/finally

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <johannh@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.075
X-Spam-Evidence '*H*': 0.85; '*S*': 0.00; 'context': 0.04; 'through,': 0.07; 'decorator': 0.09; 'dependency': 0.09; 'generators': 0.09; 'reply-to:addr:comp.lang.python': 0.09; 'to:addr:comp.lang.python': 0.09; 'wednesday,': 0.15; 'try- finally': 0.16; 'cc:addr:python-list': 0.16; 'wrote:': 0.18; 'cc:no real name:2**0': 0.20; 'header:In-Reply-To:1': 0.22; 'correct,': 0.23; 'referring': 0.23; 'cc:2**0': 0.24; 'object,': 0.24; 'thanks.': 0.26; 'yield': 0.29; 'cc:addr:python.org': 0.29; 'generally': 0.30; 'construct': 0.30; 'second,': 0.30; 'semantics': 0.30; 'syntax,': 0.30; 'changes': 0.32; 'header:User- Agent:1': 0.33; 'there': 0.33; 'subject:/': 0.35; 'but': 0.37; 'run': 0.37; 'received:google.com': 0.37; 'received:209.85': 0.38; 'created': 0.38; 'received:209': 0.40; 'happens': 0.40; 'within': 0.60; 'more': 0.61; 'illegal': 0.63; 'from:no real name:2**0': 0.63; 'guarantee': 0.65; 'believe': 0.65; '2012': 0.67; '11,': 0.68; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'reply-to:addr:googlegroups.com': 0.74; 'irrelevant.': 0.84; 'passage': 0.84; 'received:209.85.213.184': 0.84; 'received:mail- yx0-f184.google.com': 0.84; 'subject:try': 0.84; 'light.': 0.91
Newsgroups comp.lang.python
Date Wed, 11 Jan 2012 09:30:58 -0800 (PST)
In-Reply-To <mailman.4658.1326302452.27778.python-list@python.org>
Complaints-To groups-abuse@google.com
Injection-Info glegroupsg2000goo.googlegroups.com; posting-host=64.22.160.1; posting-account=Hml8lgoAAAAqvUa2ECJMHkzON20UWKgQ
References <10841855.1646.1326296715536.JavaMail.geo-discussion-forums@yqiz15> <mailman.4658.1326302452.27778.python-list@python.org>
User-Agent G2/1.0
X-Google-Web-Client true
MIME-Version 1.0
Subject Re: contextlib.contextmanager and try/finally
From johannh@gmail.com
To comp.lang.python@googlegroups.com
Content-Type text/plain; charset=ISO-8859-1
Content-Transfer-Encoding quoted-printable
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
Reply-To comp.lang.python@googlegroups.com
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>
Message-ID <mailman.4659.1326303066.27778.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1326303066 news.xs4all.nl 6849 [2001:888:2000:d::a6]:36838
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:18840

Show key headers only | View raw


On Wednesday, January 11, 2012 11:20:19 AM UTC-6, Ian wrote:
> 
> Second, I believe that passage is not referring to the contextmanager
> decorator specifically, but more generally to the changes that were
> made to allow generators to yield from within a try-finally construct
> (previously this would have been illegal syntax, since there was no
> way to guarantee the finally block would be performed).

Thanks.  You and Robert have shown me the light.  That paragraph was talking about the finalization that happens to a suspended generator when it is GC'd.  Meanwhile, the contextmanager decorator ensures that its generator is run all the way through, so it would never be left in a suspended state, so its GC/finalization semantics are irrelevant. (Please correct, if wrong.)

(Neil: I understood that it created a context manager object, but I had been reading the quoted paragraph to mean that by going through a generator the decorator was re-introducing a dependency on GC time.  But I was wrong.)

Regards,
Johann

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


Thread

contextlib.contextmanager and try/finally johannh@gmail.com - 2012-01-11 07:45 -0800
  Re: contextlib.contextmanager and try/finally Neil Cerutti <neilc@norwich.edu> - 2012-01-11 16:46 +0000
  Re: contextlib.contextmanager and try/finally Robert Kern <robert.kern@gmail.com> - 2012-01-11 17:14 +0000
  Re: contextlib.contextmanager and try/finally Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-11 10:20 -0700
    Re: contextlib.contextmanager and try/finally johannh@gmail.com - 2012-01-11 09:30 -0800
    Re: contextlib.contextmanager and try/finally johannh@gmail.com - 2012-01-11 09:30 -0800
  RE: contextlib.contextmanager and try/finally "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-01-31 21:07 +0000
  RE: contextlib.contextmanager and try/finally Peter Otten <__peter__@web.de> - 2012-01-31 23:02 +0100
  Re: contextlib.contextmanager and try/finally Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-31 15:09 -0700
    Re: contextlib.contextmanager and try/finally Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-02-01 02:15 +0000

csiph-web