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


Groups > comp.lang.python > #19658

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!tudelft.nl!txtfeed1.tudelft.nl!multikabel.net!newsfeed20.multikabel.net!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <ramit.prasad@jpmorgan.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.008
X-Spam-Evidence '*H*': 0.98; '*S*': 0.00; 'context': 0.04; 'mentioned,': 0.04; 'completeness': 0.05; 'fashion.': 0.07; 'to:name:python-list@python.org': 0.15; '712': 0.16; '>like': 0.16; 'closes': 0.16; 'currencies': 0.16; 'disclaimers': 0.16; 'disclaimers,': 0.16; 'from:addr:jpmorgan.com': 0.16; 'received:155.180': 0.16; 'received:159.53': 0.16; 'received:169.70': 0.16; 'received:169.70.184': 0.16; 'received:exchad.jpmchase.net': 0.16; 'received:jpmchase.com': 0.16; 'received:jpmchase.net': 0.16; 'securities,': 0.16; 'url:disclosures': 0.16; 'url:jpmorgan': 0.16; '(i.e.': 0.17; 'written': 0.19; 'header:In-Reply-To:1': 0.22; 'timely': 0.25; 'explicitly': 0.28; 'received:155': 0.30; 'received:159': 0.30; 'yields': 0.30; 'received:169': 0.30; 'received:169.254': 0.30; 'accuracy': 0.32; 'to:addr:python-list': 0.33; 'subject:/': 0.34; 'phone:': 0.35; 'something': 0.35; 'header:Received:8': 0.36; 'thread': 0.36; 'charset:us-ascii': 0.36; 'but': 0.37; 'another': 0.37; 'happens': 0.37; 'called': 0.39; 'subject:: ': 0.39; 'to:addr:python.org': 0.40; 'offers': 0.60; 'your': 0.61; 'subject': 0.62; 'information,': 0.69; 'legal': 0.71; 'url:email': 0.72; 'sale': 0.75; 'bank': 0.76; 'guaranteed': 0.77; 'investment': 0.77; 'purchase': 0.84; 'received:169.254.8': 0.84; 'subject:try': 0.84; 'sys.exit()?': 0.84
X-DKIM OpenDKIM Filter v2.1.3 sf1.jpmchase.com q0VLEuZK003908
DKIM-Signature v=1; a=rsa-sha256; c=simple/simple; d=jpmorgan.com; s=smtpout; t=1328044496; bh=d+HJ5P9QLYBupXoCXI366wUjYiGMbOArnqe4mAbOUBc=; h=From:To:Subject:Date:Message-ID:References:In-Reply-To: Content-Transfer-Encoding:MIME-Version:Content-Type; b=jDBPXlTkMHxljQRxHHdXfcAc02J3maCjcrgHqBG6E6WqzAr9VTDCO9HJDtLvZ5m6i 7xfnpA4A3GH1amboZA0f0iT550nO/e5sQC20baeSCzgEtpDXCkh3FAZo1DHXZ6eRp+ m/hld6tGRx7+NQNzTiJbzZkgRdmS4dxqpT4fSPkA=
From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
To "python-list@python.org" <python-list@python.org>
Subject RE: contextlib.contextmanager and try/finally
Thread-Topic contextlib.contextmanager and try/finally
Thread-Index AQHM0HjMkUIeqgdcHEe+aQ42f6PS/5YHvXWAgB9ZEmA=
Date Tue, 31 Jan 2012 21:07:02 +0000
References <10841855.1646.1326296715536.JavaMail.geo-discussion-forums@yqiz15> <CALwzidntt7n1PskCuoHaehCR1+K_F13YxdGapW2fWQtykNYm+A@mail.gmail.com>
In-Reply-To <CALwzidntt7n1PskCuoHaehCR1+K_F13YxdGapW2fWQtykNYm+A@mail.gmail.com>
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-originating-ip [10.67.79.38]
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
X-DLP-FWD Yes
Content-Type text/plain; charset="us-ascii"
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.5259.1328046066.27778.python-list@python.org> (permalink)
Lines 16
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1328046066 news.xs4all.nl 6885 [2001:888:2000:d::a6]:53202
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19658

Show key headers only | View raw


>Like Neil mentioned, a contextmanager generator is wrapped with an
>__exit__ method that is guaranteed to be called and that explicitly
>resumes or closes the generator.  So as long as your contextmanager
>generator is properly written (i.e. it yields exactly once), the
>finally block will execute in a timely fashion.

Is that true even in the face of something like sys.exit()?
What happens if 1) sys.exit is called while in the same thread
2) sys.exit is called from another thread but while this thread
is in context manager?

Ramit

Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--

This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

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