Eugene Lazutkin wrote:
It looks pretty much like the patch #463, which fixed multi-threading problem for MySQL. AFAIR, somebody ported it to PostGres.
That was me: http://code.djangoproject.com/ticket/900 However the patch there wasn't included (yet?).
Now sqlite has similar problem. Maybe we should abstract it out somehow and use in all problematic backends?
The problem is not with any particular backend. All processes access the connection that is created only once. So if you have multi-threaded web server you inevitably get the same instance of a connection for every thread in one web server process.
What is different is the way that it is solved for different backends. As I remember in your patch for MySQL you create the connection for each thread and control their lifetime. My patch for Postgres takes advantage of psycopg connection being thread-safe and just keeps counter of threads to prevent premature close. For SQLite I'd took your approach since it explicitely prevents multi-thread access to connections.
In any case the workaround for now would be using non-threaded server (e.g Apache with "preforked worker"). Then you a guarranteed that only one thread uses on instance of the connection.