[pysqlite] Releasing GIL around sqlite3_prepare

Ben.Cottrell at nominum.com Ben.Cottrell at nominum.com
Sat Aug 23 00:27:26 CEST 2008


Hi,

I noticed that not all calls to sqlite3_prepare() in pysqlite 2.3.2
(which is the version that ships with both Python 2.5.1 and 2.5.2)
are wrapped with Py_BEGIN_ALLOW_THREADS/Py_END_ALLOW_THREADS.

This can cause spurious timeouts ("OperationalError: database is
locked", because if sqlite3_prepare() finds the database locked by
another Python thread, it will invoke the sqlite busy handler, sleep,
and try again -- not releasing the GIL. The thread that owns the lock
will not be able to acquire the GIL, so it will not have a chance to
finish what it's doing and release the database lock so that the first
thread could make progress.

Is there a reason for this? Would the attached patch be sufficient
to fix it? Can anyone think of other sqlite3 API calls that can block,
that I should check to make sure pysqlite does not call them without
releasing the GIL?

(this patch is against the Python source distribution -- let me know
if I should make a patch against pysqlite-2.4.1 instead)

Thanks!

	~Ben
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/x-patch
Size: 1616 bytes
Desc: not available
Url : http://itsystementwicklung.de/pipermail/list-pysqlite/attachments/20080822/ff45013c/attachment.bin 


More information about the list-pysqlite mailing list