Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'explicitly': 0.05; 'nicely': 0.07; 'subject:help': 0.08; 'assumed': 0.09; 'exception.': 0.09; 'cc:addr:python-list': 0.11; 'clause,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'simplest': 0.16; 'terminate.': 0.16; 'unexpected': 0.16; 'exception': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'code,': 0.22; 'example': 0.22; 'aug': 0.22; 'cc:addr:python.org': 0.22; 'cc:2**0': 0.24; 'source': 0.25; 'header:In-Reply-To:1': 0.27; 'idea': 0.28; 'chris': 0.29; 'am,': 0.29; 'thus': 0.29; 'database,': 0.30; 'message-id:@mail.gmail.com': 0.30; 'program,': 0.31; 'that.': 0.31; 'subject:some': 0.31; 'terminate': 0.31; 'could': 0.34; 'connection': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'should': 0.36; 'writes': 0.38; 'handle': 0.38; 'issue': 0.38; 'resource': 0.38; 'anything': 0.39; 'release': 0.40; 'entire': 0.61; 'simple': 0.61; 'back': 0.62; 'kind': 0.63; 'finally': 0.65; 'within': 0.65; 'close': 0.67; 'reads': 0.68; 'real-world': 0.68; '10:32': 0.84; 'to:none': 0.92 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type; bh=prdW9knkvNt+Xm8mlfO9piWBvu4KUOuu0Vk/CiDpX6k=; b=nDaRKD+X7nWbsB8PMn88EKYX5UBLZTz3cCoJ2T0eMHjC5H0tM6Co8OiYy1PaXT+2vL EGaGfMJg5dfNtrNWKN8NLEBnxi6j45JGcESn0HsWoeN+iwjA2/bD7Cwh2DoVFMpHG5QP AtWJJ3JG1CBLJTCQeEsnxNOMGNPyeBylVBw+1Bony3Ns3SzQ703prvlFaiVErcY6aMLn NSbUKkhkgaxRyqXLpHzBiWeorC2Xkcv7XTilUw4oaRDKImVGXwhX1sIHkayUGS+OGIZV 6/09YvMzaJJNQsc13NqNofdwCO42Z9OeAUccvu+L7MN4Mls7/uhMBOoXKJqqQpKulDmm tOtA== MIME-Version: 1.0 X-Received: by 10.42.96.132 with SMTP id j4mr16252578icn.16.1407544760571; Fri, 08 Aug 2014 17:39:20 -0700 (PDT) In-Reply-To: References: Date: Sat, 9 Aug 2014 10:39:20 +1000 Subject: Re: Newbie needing some help From: Chris Angelico Cc: "python-list@python.org" Content-Type: text/plain; charset=UTF-8 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 20 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1407544763 news.xs4all.nl 2920 [2001:888:2000:d::a6]:57272 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:75919 On Sat, Aug 9, 2014 at 10:32 AM, Chris Kaynor wrote: > The main issue I can see with that idea is that the exception will keep a > reference to the database connection (as with all locals), so unless you > explicitly close it within a finally clause, the database connection could > still be left hanging, and thus no rollback will occur. To clarify: The simple example I used there was assumed to be the entire program, meaning that the process will terminate on exception. No worries about resource release then! This kind of model works nicely for anything that reads from one source and writes into the database, or processes data from the database back into the database, or anything like that. The general assumption is that an unexpected exception should be treated as fatal - just write to the console and terminate. While this might seem like the simplest 1% of cases, it's able to handle a lot of real-world situations. And since it takes no extra code, it's the perfect way to start :) ChrisA