From e6872eb41710f14d35616b168f21d85c96d26ff7 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Gerhard=20H=C3=A4ring?= Date: Fri, 12 Sep 2008 22:33:22 +0000 Subject: [PATCH] Issue #3846: Release GIL during calls to sqlite3_prepare. This improves concurrent access to the same database file from multiple threads/processes. --- Misc/NEWS | 4 ++++ Modules/_sqlite/cursor.c | 2 ++ Modules/_sqlite/statement.c | 4 ++++ 3 files changed, 10 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index aca06f2a5b..a31bcd5f44 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -151,6 +151,10 @@ Extension Modules - Issue #3103: Reduced globals symbols used by sqlite3 module and made sure all remaining ones have "pysqlite_" prefix. +- Issue #3846: Release the GIL during sqlite3_prepare calls. This improves + concurrent access to the same SQLite database from multiple + threads/processes. + Tests ----- diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index 1bf27d7901..6572a559a6 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -790,11 +790,13 @@ PyObject* pysqlite_cursor_executescript(pysqlite_Cursor* self, PyObject* args) } statement_completed = 1; + Py_BEGIN_ALLOW_THREADS rc = sqlite3_prepare(self->connection->db, script_cstr, -1, &statement, &script_cstr); + Py_END_ALLOW_THREADS if (rc != SQLITE_OK) { _pysqlite_seterror(self->connection->db, NULL); goto error; diff --git a/Modules/_sqlite/statement.c b/Modules/_sqlite/statement.c index dae83d4586..f200c56399 100644 --- a/Modules/_sqlite/statement.c +++ b/Modules/_sqlite/statement.c @@ -79,11 +79,13 @@ int pysqlite_statement_create(pysqlite_Statement* self, pysqlite_Connection* con sql_cstr = PyString_AsString(sql_str); + Py_BEGIN_ALLOW_THREADS rc = sqlite3_prepare(connection->db, sql_cstr, -1, &self->st, &tail); + Py_END_ALLOW_THREADS self->db = connection->db; @@ -328,11 +330,13 @@ int pysqlite_statement_recompile(pysqlite_Statement* self, PyObject* params) sql_cstr = PyString_AsString(self->sql); + Py_BEGIN_ALLOW_THREADS rc = sqlite3_prepare(self->db, sql_cstr, -1, &new_st, &tail); + Py_END_ALLOW_THREADS if (rc == SQLITE_OK) { /* The efficient sqlite3_transfer_bindings is only available in SQLite -- 2.49.0