-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