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


Groups > comp.lang.python > #75923

Re: Newbie needing some help

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <ckaynor@zindagigames.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.031
X-Spam-Evidence '*H*': 0.94; '*S*': 0.00; 'finally:': 0.07; 'odd': 0.07; 'subject:help': 0.08; 'except:': 0.09; 'try:': 0.09; 'cc:addr:python-list': 0.11; 'behavior,': 0.16; 'reasonably': 0.16; 'success:': 0.16; 'exception': 0.16; 'sat,': 0.16; 'wrote:': 0.18; 'commit': 0.19; 'aug': 0.22; 'email addr:gmail.com&gt;': 0.22; 'cc:addr:python.org': 0.22; '(or': 0.24; 'cc:2**0': 0.24; '&gt;': 0.26; 'possibly': 0.26; 'header:In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'raise': 0.29; 'absolute': 0.30; 'statement': 0.30; 'timely': 0.30; 'message-id:@mail.gmail.com': 0.30; 'subject:some': 0.31; 'received:209.85.212': 0.32; 'fri,': 0.33; "i'd": 0.34; 'could': 0.34; 'problem': 0.35; 'received:209.85': 0.35; 'connection': 0.35; 'transaction': 0.35; 'case,': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'false': 0.36; 'should': 0.36; 'error.': 0.37; 'received:209': 0.37; 'server': 0.38; 'skip:& 10': 0.38; 'actions': 0.38; 'pm,': 0.38; 'track': 0.38; 'rather': 0.38; 'either': 0.39; 'even': 0.60; 'is.': 0.60; 'completed': 0.61; 'success': 0.61; 'back': 0.62; 'different': 0.65; 'to:addr:gmail.com': 0.65; 'close': 0.67; 'manner': 0.72; 'bare': 0.84; 'or:': 0.84; 'imagine': 0.93
X-Google-DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-type; bh=19oI5doz1MIgbbiTUsSmoHxmFMo7yXuDoU5hv5H6p3Y=; b=SqQYdGlnrPVnfoudonft6NHmwe4mqhssG9LgU7cj6zw8/iSfHuuWCQryDpwfDym3XA d4HgQ2zBNjah+XlqtpNz+bGDLOGMU2TdPsAGJmI6OWrADKeIvZT8v6IJataXavslf2By V7kDMirXQd8LgIChuOVZmdA8K2/G3elXuiOOHKvOVHIrmPenOgDIOolC+xnsimF8isI7 DVExxjNiw/gJOzd3CUGvfsCIL4Tv6SpAAVVKsoUnnvhlOLrcP4e9hI7uaUC2WYNfTbX/ lnujD8+2I0GKF2t5WTuEQB7ITfYfCyIvsQWALEqVjC/7P+pi6gXnjmU3aWEkSk8xCKQH dYCw==
X-Gm-Message-State ALoCoQkTFt0lGP/d7U3exaYFennAsYL+xaCCyXwi2n4YTJzFq4QlGPEfaL2m6dNUE9Qvi/5B5MLE
X-Received by 10.194.22.166 with SMTP id e6mr36121951wjf.88.1407542159261; Fri, 08 Aug 2014 16:55:59 -0700 (PDT)
MIME-Version 1.0
In-Reply-To <CAPTjJmq=dydhFEooRHqG2UaHTREjJSyqk9McuDYhc8PRjSzTgA@mail.gmail.com>
References <CANhUTb9tEnT=uTMhdA+Fd2zJTMauo1BWkX2dgcE0dG_H5arx9Q@mail.gmail.com> <CALvWhxtWyQw08TBVOTDhfFjm0=PP19QY3Yv-v74Q2T=ndyW91g@mail.gmail.com> <CAPTjJmq=dydhFEooRHqG2UaHTREjJSyqk9McuDYhc8PRjSzTgA@mail.gmail.com>
From Chris Kaynor <ckaynor@zindagigames.com>
Date Fri, 8 Aug 2014 16:55:39 -0700
Subject Re: Newbie needing some help
To Chris Angelico <rosuav@gmail.com>
Content-Type multipart/alternative; boundary=047d7b5d912768d933050026f2df
Cc "python-list@python.org" <python-list@python.org>
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://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 <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.12778.1407551506.18130.python-list@python.org> (permalink)
Lines 123
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1407551506 news.xs4all.nl 2890 [2001:888:2000:d::a6]:53179
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:75923

Show key headers only | View raw


[Multipart message — attachments visible in raw view] - view raw

On Fri, Aug 8, 2014 at 4:38 PM, Chris Angelico <rosuav@gmail.com> wrote:

> On Sat, Aug 9, 2014 at 8:01 AM, Chris Kaynor <ckaynor@zindagigames.com>
> wrote:
> > However, I'd recommend re-raising the exception after rolling back the
> > transaction with a bare "raise" statement right after the db.rollback()
> - at
> > the absolute minimum, you should log the error. This will likely let you
> see
> > what your problem is.
>
> AIUI, aborting the process with an uncaught exception would roll back
> implicitly, so there's no need to "bare except, roll back, bare
> raise". But even if that's not the case, I would be looking at a
> try/finally for this, rather than a try/except/raise.
>

I would imagine that on connection close, the server would rollback any
uncommitted transactions, however that presumes that the connection close
is completed in a reasonably timely manner (with a try...finally for
closing, it should be).

This is one case where I think try...except/raise is better than
try...finally. If you use try...finally to rollback, you'd have to either
track whether you committed, or you'd rollback with no actions (or possibly
a committed action, which could have odd behavior, depending on the
implementation)

try:
    action
    commit
except:
    rollback
    raise

I feel is better than:

try:
    action
    commit
finally:
    rollback

or:

success = False
try:
    action
    commit
    success = True
finally:
    if success:
        rollback

and is very different than:

try:
    action
finally:
    commit

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


Thread

Re: Newbie needing some help Chris Kaynor <ckaynor@zindagigames.com> - 2014-08-08 16:55 -0700

csiph-web