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


Groups > comp.lang.python > #51737

Best practice for connections and cursors

Path csiph.com!usenet.pasdenom.info!dedibox.gegeweb.org!gegeweb.eu!nntpfeed.proxad.net!proxad.net!feeder2-2.proxad.net!npeer.de.kpn-eurorings.net!npeer-ng0.de.kpn-eurorings.net!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <jcasale@activenetwerx.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.004
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'python,': 0.02; 'insert': 0.05; 'nested': 0.07; 'assumed': 0.09; 'cursor': 0.09; 'debugger': 0.09; 'defines': 0.09; 'exit': 0.09; 'python': 0.11; 'creates': 0.14; 'posted': 0.15; '(big': 0.16; 'early.': 0.16; 'invoking': 0.16; 'mess,': 0.16; 'received:172.18.0': 0.16; 'singleton': 0.16; 'sqlite': 0.16; 'temp': 0.16; 'bit': 0.19; 'module': 0.19; 'commit': 0.19; 'seems': 0.21; 'select': 0.22; 'import': 0.22; 'to:name:python-list@python.org': 0.22; 'this?': 0.23; 'oriented': 0.24; "i've": 0.25; 'second': 0.26; 'work.': 0.31; 'code': 0.31; 'table,': 0.31; 'yields': 0.31; 'anyone': 0.31; 'file': 0.32; 'thanks!': 0.32; 'another': 0.32; 'open': 0.33; 'comment': 0.34; 'table': 0.34; 'connection': 0.35; 'created': 0.35; 'but': 0.35; 'there': 0.35; 'yield': 0.36; 'method': 0.36; 'charset:us-ascii': 0.36; 'list': 0.37; 'level': 0.37; 'expected': 0.38; 'to:addr :python-list': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'users': 0.40; 'received:unknown': 0.61; 'simply': 0.61; 'more': 0.64; 'within': 0.65; 'here': 0.66; 'records.': 0.68; 'obvious': 0.74; 'leverages': 0.84; 'viable': 0.84; 'indicator': 0.91; 'opens': 0.91; 'subject:Best': 0.91; 'connection,': 0.95
X-Cloudmark-SP-Filtered true
X-Cloudmark-SP-Result v=1.1 cv=KbdnvV9g8TRf6O+NCh6TOyF5LS0weEPBhaAycnKeCs0= c=1 sm=1 a=P90J6pEA2ccA:10 a=LZI1Jliv4X8A:10 a=7PYXob_7ZXMA:10 a=BLceEmwcHowA:10 a=kj9zAlcOel0A:10 a=xqWC_Br6kY4A:10 a=oNw28mxuUhXRB3mVwYQ4Ag==:17 a=sM9F5RJZK0FVxKiKVS0A:9 a=CjuIK1q_8ugA:10 a=HpAAvcLHHh0Zw7uRqdWCyQ==:117
From "Joseph L. Casale" <jcasale@activenetwerx.com>
To "python-list@python.org" <python-list@python.org>
Subject Best practice for connections and cursors
Thread-Topic Best practice for connections and cursors
Thread-Index AQHOjsdwoB2d8GS7N0aIL+r6i2Qjnw==
Date Thu, 1 Aug 2013 15:05:08 +0000
Accept-Language en-US
Content-Language en-US
X-MS-Has-Attach
X-MS-TNEF-Correlator
x-originating-ip [172.18.0.4]
Content-Type text/plain; charset="us-ascii"
Content-Transfer-Encoding quoted-printable
MIME-Version 1.0
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.80.1375369534.1251.python-list@python.org> (permalink)
Lines 43
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1375369534 news.xs4all.nl 15925 [2001:888:2000:d::a6]:51526
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:51737

Show key headers only | View raw


I posted this to the sqlite list but I suspect there are more C oriented users on
that list than Python, hopefully someone here can shed some light on this one.

I have created a python module that I import within several other modules that
simply opens a connection to an sqlite file and defines several methods which
each open a cursor before they either select or insert data.

As the module opens a connection, wherever I import it I call a commit against
the connection after invoking any methods that insert or change data.

Seems I've made a proper mess, one of the modules causes a 5 second delay
at import (big indicator there) and one of the modules calls a method that yields
data while calling other methods as it iterates. Each of these methods opens its
own cursor. One of which during some processing calls another method which
opens a cursor and creates a temp table and this corrupts the top level cursor
and causes its yield to exit early.

If I open a debugger just as the top level method begins to yield, I can pull all
the expected records. It seems to be one of the nested methods that leverages
the singleton connection to the sqlite db, once it opens its own cursor and creates
a temp table, things go south. Comment out its cursor and code and things work.

A bit vague I know, but does anyone see the obvious mistake? I assumed the module
setting up a singleton connection was a perfectly viable way to accomplish this?

Thanks!
jlc

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


Thread

Best practice for connections and cursors "Joseph L. Casale" <jcasale@activenetwerx.com> - 2013-08-01 15:05 +0000
  Re: Best practice for connections and cursors Neil Cerutti <neilc@norwich.edu> - 2013-08-01 15:20 +0000

csiph-web