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: 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" To: "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> In-Reply-To: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 >Like Neil mentioned, a contextmanager generator is wrapped with an=0D=0A>_= _exit__ method that is guaranteed to be called and that explicitly=0D=0A>re= sumes or closes the generator=2E So as long as your contextmanager=0D=0A>g= enerator is properly written (i=2Ee=2E it yields exactly once), the=0D=0A>f= inally block will execute in a timely fashion=2E=0D=0A=0D=0AIs that true ev= en in the face of something like sys=2Eexit()?=0D=0AWhat happens if 1) sys= =2Eexit is called while in the same thread=0D=0A2) sys=2Eexit is called fro= m another thread but while this thread=0D=0Ais in context manager?=0D=0A=0D= =0ARamit=0D=0A=0D=0ARamit Prasad | JPMorgan Chase Investment Bank | Currenc= ies Technology=0D=0A712 Main Street | Houston, TX 77002=0D=0Awork phone: 71= 3 - 216 - 5423=0D=0A=0D=0A--=0D=0A=0D=0AThis email is confidential and subj= ect to important disclaimers and=0D=0Aconditions including on offers for th= e purchase or sale of=0D=0Asecurities, accuracy and completeness of informa= tion, viruses,=0D=0Aconfidentiality, legal privilege, and legal entity disc= laimers,=0D=0Aavailable at http://www=2Ejpmorgan=2Ecom/pages/disclosures/em= ail=2E