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


Groups > comp.lang.python > #51737 > unrolled thread

Best practice for connections and cursors

Started by"Joseph L. Casale" <jcasale@activenetwerx.com>
First post2013-08-01 15:05 +0000
Last post2013-08-01 15:20 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  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

#51737 — Best practice for connections and cursors

From"Joseph L. Casale" <jcasale@activenetwerx.com>
Date2013-08-01 15:05 +0000
SubjectBest practice for connections and cursors
Message-ID<mailman.80.1375369534.1251.python-list@python.org>
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

[toc] | [next] | [standalone]


#51738

FromNeil Cerutti <neilc@norwich.edu>
Date2013-08-01 15:20 +0000
Message-ID<b5vcm0F8577U1@mid.individual.net>
In reply to#51737
On 2013-08-01, Joseph L. Casale <jcasale@activenetwerx.com> wrote:
> 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?

My one db application started out creating a new connection to
the db (sqlite3) for every select and insert. When I converted it
to maintaining it's own single connection and creating new
cursors instead it was a huge speed increase. So I too am
interested in the answers you'll hopefully be getting. I have no
plans for utilizing concurrent access to the db, but maybe I'll
want to someday.

-- 
Neil Cerutti

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web