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: 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" To: "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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: 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 I posted this to the sqlite list but I suspect there are more C oriented us= ers on=0A= that list than Python, hopefully someone here can shed some light on this o= ne.=0A= =0A= I have created a python module that I import within several other modules t= hat=0A= simply opens a connection to an sqlite file and defines several methods whi= ch=0A= each open a cursor before they either select or insert data.=0A= =0A= As the module opens a connection, wherever I import it I call a commit agai= nst=0A= the connection after invoking any methods that insert or change data.=0A= =0A= Seems I've made a proper mess, one of the modules causes a 5 second delay= =0A= at import (big indicator there) and one of the modules calls a method that = yields=0A= data while calling other methods as it iterates. Each of these methods open= s its=0A= own cursor. One of which during some processing calls another method which= =0A= opens a cursor and creates a temp table and this corrupts the top level cur= sor=0A= and causes its yield to exit early.=0A= =0A= If I open a debugger just as the top level method begins to yield, I can pu= ll all=0A= the expected records. It seems to be one of the nested methods that leverag= es=0A= the singleton connection to the sqlite db, once it opens its own cursor and= creates=0A= a temp table, things go south. Comment out its cursor and code and things w= ork.=0A= =0A= A bit vague I know, but does anyone see the obvious mistake? I assumed the = module=0A= setting up a singleton connection was a perfectly viable way to accomplish = this?=0A= =0A= Thanks!=0A= jlc=