are there pros or contras, keeping a connection to a (sqlite) database ?

CM cmpython at
Thu Sep 9 00:29:56 CEST 2010

On Sep 8, 1:09 pm, Stef Mientki <stef.mien... at> wrote:
>  hello,
> I wrap my database in some class, and on creation of the instance, a connection to the database is
> created,
> and will stay connected until the program exists, something like this:
>     self.conn = sqlite3.connect ( self.filename )
> Now I wonder if there are pros or contras to keep the connection to the database continuously  "open" ?
> thanks,
> Stef Mientki

I do the same thing--good to hear from John that keeping it open is

But another question that this provokes, at least for me is:  what
happens when you call .connect() on the same database multiple times
from within different parts of the same app?  Is that bad?  And is it
that there now multiple connections to the database, or one connection
that has multiple names in different namespaces within the app?

I'm not even sure what a "connection" really is; I assumed it was
nothing more than a rule that says to write to the database with the
file named in the parentheses.

Further elaboration from the community would be helpful.


More information about the Python-list mailing list