Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #50223
| Path | csiph.com!usenet.pasdenom.info!news.franciliens.net!news.muarf.org!nntpfeed.proxad.net!proxad.net!feeder1-2.proxad.net!usenet-fr.net!nerim.net!novso.com!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <ian.g.kelly@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.193 |
| X-Spam-Level | * |
| X-Spam-Evidence | '*H*': 0.65; '*S*': 0.04; 'method.': 0.07; 'def': 0.12; 'factory': 0.16; 'merely': 0.16; 'wrote:': 0.18; 'separate': 0.22; 'updating': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'skip:@ 10': 0.30; 'message- id:@mail.gmail.com': 0.30; 'factor': 0.31; 'probably': 0.32; 'skip:c 30': 0.32; 'skip:d 20': 0.34; "i'd": 0.34; 'received:google.com': 0.35; 'yield': 0.36; 'to:addr:python-list': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; 'access,': 0.60; "you're": 0.61; 'frank': 0.68; 'jul': 0.74; 'repeat': 0.74; 'reading,': 0.84; 'writing,': 0.84; '2013': 0.98 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=Xfn3a422+u8qKGGl1la19PqFWWDnBp3ZOXFzWc+59N8=; b=Coa9CYW3gd7wAhpyBDAj4DVwUML7Sw+V8Fr3rYnCOg4MYIaymL61EdsHpUyKn/7NE4 a9DM86oReGGW3bm6m+F5YfP7lXfjeGKtyxTh6idsHeACCmVRxQpz1W4AyaAW639roEyN TUpnhHQClAtCTpUvC0dbEfdRYpY0KWLzABwN6t4gOAq8o2/jeABkc17NaycfZejzuaPX L8Gjv76Eed9k2cQVAaTvFDqjshyEUXfUlHMFZ10TTGdTHwH1DOZyyEucf14zN1oowJ2S sOTMPf/Ln1DhbudytWzElIsl2bRM5kGLnYa1IHHCDl5jVRL93FGDbb8uobwF6H16i2Qm QKkQ== |
| X-Received | by 10.68.164.225 with SMTP id yt1mr24680537pbb.195.1373356629254; Tue, 09 Jul 2013 00:57:09 -0700 (PDT) |
| MIME-Version | 1.0 |
| In-Reply-To | <krgefq$gji$1@ger.gmane.org> |
| References | <51d4eb9c$0$29999$c3e8da3$5496439d@news.astraweb.com> <mailman.4200.1372910878.3114.python-list@python.org> <51d508ed$0$6512$c3e8da3$5496439d@news.astraweb.com> <mailman.4208.1372916885.3114.python-list@python.org> <51d5a504$0$29999$c3e8da3$5496439d@news.astraweb.com> <CAPTjJmpgmABYwn0xB4T-9VbYMP=8JfpRcy8TPSerzyGvzPbMmA@mail.gmail.com> <alpine.DEB.2.02.1307070759350.18702@gilgamesh> <mailman.4357.1373204606.3114.python-list@python.org> <krg4k4$tea$1@dont-email.me> <mailman.4423.1373346452.3114.python-list@python.org> <krg91s$e6j$1@dont-email.me> <CAPTjJmqkmFd4-Jpugr-vubuB6riBV6K_Mwnxc_U3CVaBr_Wgbg@mail.gmail.com> <krgefq$gji$1@ger.gmane.org> |
| From | Ian Kelly <ian.g.kelly@gmail.com> |
| Date | Tue, 9 Jul 2013 01:56:29 -0600 |
| Subject | Re: Default scope of variables |
| To | Python <python-list@python.org> |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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 | <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.4437.1373356631.3114.python-list@python.org> (permalink) |
| Lines | 23 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1373356631 news.xs4all.nl 15984 [2001:888:2000:d::a6]:37638 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:50223 |
Show key headers only | View raw
On Tue, Jul 9, 2013 at 1:35 AM, Frank Millman <frank@chagford.com> wrote:
> When any of them need any database access, whether for reading or for
> updating, they execute the following -
>
> with db_session as conn:
> conn.transaction_active = True # this line must be added if
> updating
> conn.cur.execute(__whatever__)
I'd probably factor out the transaction_active line into a separate
DbSession method.
@contextmanager
def updating(self):
with self as conn:
conn.transaction_active = True
yield conn
Then you can do "with db_session" if you're merely reading, or "with
db_session.updating()" if you're writing, and you don't need to repeat
the transaction_active line all over the place.
I would also probably make db_session a factory function instead of a global.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Default scope of variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-04 03:27 +0000
Re: Default scope of variables Chris Angelico <rosuav@gmail.com> - 2013-07-04 14:07 +1000
Re: Default scope of variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-04 05:32 +0000
Re: Default scope of variables Chris Angelico <rosuav@gmail.com> - 2013-07-04 15:47 +1000
Re: Default scope of variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-04 16:38 +0000
Re: Default scope of variables Chris Angelico <rosuav@gmail.com> - 2013-07-05 02:58 +1000
Re: Default scope of variables Wayne Werner <wayne@waynewerner.com> - 2013-07-07 08:13 -0500
Re: Default scope of variables Chris Angelico <rosuav@gmail.com> - 2013-07-07 23:43 +1000
Re: Default scope of variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-07 16:03 +0000
Re: Default scope of variables Chris Angelico <rosuav@gmail.com> - 2013-07-08 10:46 +1000
Re: Default scope of variables alex23 <wuwei23@gmail.com> - 2013-07-09 14:52 +1000
Re: Default scope of variables Chris Angelico <rosuav@gmail.com> - 2013-07-09 15:07 +1000
Re: Default scope of variables alex23 <wuwei23@gmail.com> - 2013-07-09 16:08 +1000
Re: Default scope of variables Chris Angelico <rosuav@gmail.com> - 2013-07-09 16:13 +1000
Re: Default scope of variables "Frank Millman" <frank@chagford.com> - 2013-07-09 09:35 +0200
Re: Default scope of variables Chris Angelico <rosuav@gmail.com> - 2013-07-09 17:45 +1000
Re: Default scope of variables Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-09 01:56 -0600
Re: Default scope of variables "Frank Millman" <frank@chagford.com> - 2013-07-09 10:22 +0200
Re: Default scope of variables "Frank Millman" <frank@chagford.com> - 2013-07-09 10:38 +0200
Re: Default scope of variables Ethan Furman <ethan@stoneleaf.us> - 2013-07-09 09:07 -0700
Re: Default scope of variables Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-09 10:44 -0600
Re: Default scope of variables Ethan Furman <ethan@stoneleaf.us> - 2013-07-09 10:23 -0700
Re: Default scope of variables Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-09 12:41 -0600
Re: Default scope of variables Ethan Furman <ethan@stoneleaf.us> - 2013-07-09 12:19 -0700
Re: Default scope of variables "Frank Millman" <frank@chagford.com> - 2013-07-10 07:54 +0200
Re: Default scope of variables Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-10 09:42 -0600
Re: Default scope of variables Ethan Furman <ethan@stoneleaf.us> - 2013-07-10 08:29 -0700
Re: Default scope of variables "Frank Millman" <frank@chagford.com> - 2013-07-11 07:52 +0200
Re: Default scope of variables Ethan Furman <ethan@stoneleaf.us> - 2013-07-07 09:52 -0700
Re: Default scope of variables Ethan Furman <ethan@stoneleaf.us> - 2013-07-07 11:59 -0700
Re: Default scope of variables Chris Angelico <rosuav@gmail.com> - 2013-07-08 10:48 +1000
Re: Default scope of variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-08 02:23 +0000
Re: Default scope of variables Chris Angelico <rosuav@gmail.com> - 2013-07-08 13:11 +1000
Re: Default scope of variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-08 05:00 +0000
Re: Default scope of variables Chris Angelico <rosuav@gmail.com> - 2013-07-08 15:14 +1000
Re: Default scope of variables Peter Otten <__peter__@web.de> - 2013-07-04 08:48 +0200
Re: Default scope of variables Ian Kelly <ian.g.kelly@gmail.com> - 2013-07-04 01:12 -0600
Re: Default scope of variables Dave Angel <davea@davea.name> - 2013-07-04 03:06 -0400
Re: Default scope of variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-04 15:52 +0000
Re: Default scope of variables Rotwang <sg552@hotmail.co.uk> - 2013-07-04 17:54 +0100
Re: Default scope of variables Peter Otten <__peter__@web.de> - 2013-07-04 20:36 +0200
Re: Default scope of variables Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-05 01:04 +0100
Re: Default scope of variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-05 01:24 +0000
Re: Default scope of variables Dave Angel <davea@davea.name> - 2013-07-04 22:03 -0400
Re: Default scope of variables Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-05 03:29 +0100
Re: Default scope of variables Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-05 03:27 +0100
Re: Default scope of variables Rotwang <sg552@hotmail.co.uk> - 2013-07-05 07:28 +0100
Re: Default scope of variables Neil Cerutti <neilc@norwich.edu> - 2013-07-05 13:24 +0000
Re: Default scope of variables Chris Angelico <rosuav@gmail.com> - 2013-07-05 23:43 +1000
Re: Default scope of variables Neil Cerutti <neilc@norwich.edu> - 2013-07-05 15:36 +0000
Re: Default scope of variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-07 16:08 +0000
Re: Default scope of variables Neil Cerutti <neilc@norwich.edu> - 2013-07-08 11:54 +0000
Re: Default scope of variables Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-08 14:14 +0100
Re: Default scope of variables Lele Gaifax <lele@metapensiero.it> - 2013-07-04 14:43 +0200
Re: Default scope of variables Wayne Werner <wayne@waynewerner.com> - 2013-07-04 10:45 -0500
Re: Default scope of variables Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-04 05:30 +0100
Re: Default scope of variables Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-07-04 05:45 +0000
Re: Default scope of variables Chris Angelico <rosuav@gmail.com> - 2013-07-04 14:36 +1000
Re: Default scope of variables Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-04 06:09 +0100
Re: Default scope of variables Joshua Landau <joshua.landau.ws@gmail.com> - 2013-07-08 17:58 +0100
csiph-web