Threading issue with SQLite
Jonathan Gardner
jgardner at jonathangardner.net
Fri Jan 29 17:18:04 EST 2010
On Jan 29, 8:37 am, Alan Harris-Reid <aharrisr... at googlemail.com>
wrote:
>
> Questions...
> 1. Is there a large overhead in opening a new SQLite connection for
> each thread (ie. within each method)?
Yes, but not as bad as some other DBs.
> 2. Is there any way to use the same connection for the whole class (or
> should I forget that idea completely?)
Forget it. The thread stuff is pretty important.
> 3. When a method returns to the calling method, is the connection
> automatically closed (assuming the object is local, of course) or does
> it have to be done explicitly using connection.close()?
>
If the object falls out of scope, that is, no code anywhere can
reference it, it will be garbage collected and thus closed.
Suggestion: Use something like SQLAlchemy to manage you DB
interactions. One day, you'll move away from SQLite, and you'll be
glad you were programming at a higher level. SQLAlchemy also does
things like connection pooling and such for you.
More information about the Python-list
mailing list