Re: [sqlite] threading error in sqlite 3 in python

2010-08-04 Thread Roger Binns
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 08/04/2010 11:39 AM, Chris Hare wrote:
> I have 3.6.12 in use.  So how do I get around this error message>  It 
> prevents part of my code from executing

Easy - do no create SQLite objects (connections, cursors) in one thread and
use them in another(1).  There isn't much harm in creating new connections
and cursors as you need them, rather than ruthlessly trying to keep reusing one.

Until SQLite 3.5.9 you had to use SQLite objects in the same thread that
created them - ie this was a SQLite restriction(2).  SQLite 3.5.9 allowed
concurrent thread usage(3) although some tweaks are needed for correct
concurrent error handling (needs SQLite 3.6.5) and care when using the
SQLite API.  Since pysqlite supports older versions of SQLite (probably back
to 3.6.0!) it has the same restrictions and has not been updated to lift
them as that would require a more recent minimum SQLite version in addition
to code changes.

There is a dedicated Python SQLite group where the authors of both Python
SQLite bindings hang out (disclosure: I am one of them):

  http://groups.google.com/group/python-sqlite

My APSW bindings are completely threadsafe taking great care to get all the
threading issues correct (for example error messages require special
handling and you need to be careful with the Python GIL and SQLite database
mutex interactions).

(1) Also be careful to close objects in the same thread.  If you leave them
to close themselves when the destructor runs then it could run in a
different thread.

(2) You could reuse the objects in multiple threads providing you took great
care to not use them concurrently - ie you needed to ensure that you wrapped
everything up in mutexes.  pysqlite does have some flag you can set to tell
it that you are doing this, are absolutely sure your code is correct, and
that it shouldn't check.  It is very rare for code to be absolutely correct,
especially as it is updated over time and the consequences of being wrong
are database corruption and being hard to reproduce.

(3) Strictly speaking there isn't much actual concurrency - each database
connection has a mutex and almost all operations take that mutex so
operations are serialized.  But it does mean you don't need to do anything
in your code to ensure thread safety.

Roger
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.10 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iEYEARECAAYFAkxZ/VcACgkQmOOfHg372QTx6wCfSdzNTgNOrvC9y1Al+8Now17j
7d0An3qjIlA9jJ9x7vbBpeuUu1ioQltr
=7Ged
-END PGP SIGNATURE-
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


Re: [sqlite] threading error in sqlite 3 in python

2010-08-04 Thread Jay A. Kreibich
On Wed, Aug 04, 2010 at 01:00:02PM -0500, Chris Hare scratched on the wall:

> How do I figure out what version of sqlite3 is actually installed
> in the python install? (It is python2.6)

  If it isn't too old:

   SELECT sqlite_version();

   -j

-- 
Jay A. Kreibich < J A Y  @  K R E I B I.C H >

"Intelligence is like underwear: it is important that you have it,
 but showing it to the wrong people has the tendency to make them
 feel uncomfortable." -- Angela Johnson
___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users


[sqlite] threading error in sqlite 3 in python

2010-08-04 Thread Chris Hare

I think this is a version problem based upon the FAQ, but I get this error when 
a thred timer fires in python and I then try to access my sqlite3 database

ProgrammingError: SQLite objects created in a thread can only be used in that 
same thread.The object was created in thread id 140735088725024 and this is 
thread id 4628287488

How do I figure out what version of sqlite3 is actually installed in the python 
install? (It is python2.6)

Thanks,
Chris

___
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users