Django

Code

Ticket #1442 (closed: fixed)

Opened 2 years ago

Last modified 2 years ago

[patch] Fixing multithreading problem with various database backends

Reported by: eugene@lazutkin.com Assigned to: adrian
Component: Database wrapper Version:
Keywords: Cc:
Triage Stage: Unreviewed Has patch: 1
Needs documentation: 0 Needs tests: 0
Patch needs improvement: 0

Description

This patch supersedes tickets #463, #900, and #1237. Instead of lock-based connection pools it uses TLS (thread local storage). TLS is implemented by python 2.4 natively (threading.local), and by stub for python 2.3. The stub is taken verbatim from python 2.4.2 source distribution. I checked the license and it looks totally compatible with BSD license used by Django. Thank you Joseph Kocherhans (#1268).

The patch solves multithreading problems for MySQL (#463) and PostGreSQL (#900). I couldn't find a ticket for ADO/MSSQL and SQLite, so I didn't convert them. In general the fix is unbelievably simple:

try:
    # only exists in python 2.4+
    from threading import local
except ImportError:
    # import copy of _thread_local.py from python 2.4
    from django.utils._threading_local import local

class DatabaseWrapper(local):
...

It can be easily added for other backends, if required. (Additionally MySQL patch implements pinging connections.)

Attachments

django.threading.patch (9.2 kB) - added by eugene@lazutkin.com on 03/01/06 22:06:03.
patch for Django trunk
magic.threading.patch (9.1 kB) - added by eugene@lazutkin.com on 03/01/06 22:09:56.
patch for magic-removal branch
django.threading.2.patch (10.6 kB) - added by eugene@lazutkin.com on 03/02/06 11:56:11.
patch for trunk (includes all database backends)
magic.threading.2.patch (10.5 kB) - added by eugene@lazutkin.com on 03/02/06 11:56:59.
patch for magic-removal (includes all database backends)

Change History

03/01/06 22:06:03 changed by eugene@lazutkin.com

  • attachment django.threading.patch added.

patch for Django trunk

03/01/06 22:09:56 changed by eugene@lazutkin.com

  • attachment magic.threading.patch added.

patch for magic-removal branch

03/01/06 22:13:43 changed by eugene@lazutkin.com

I tested it on Python 2.4 and Python 2.3 (trunk) with MySQL (DreamHost setup). Please try it with PostGreSQL and magic-removal version. I imagine it just works because the patch is so small, and can be veriied manually. But just in case.

03/01/06 22:36:48 changed by eugene@lazutkin.com

  • summary changed from [patch] multithreading problem with various backends to [patch] Fixing multithreading problem with various database backends.

03/02/06 11:56:11 changed by eugene@lazutkin.com

  • attachment django.threading.2.patch added.

patch for trunk (includes all database backends)

03/02/06 11:56:59 changed by eugene@lazutkin.com

  • attachment magic.threading.2.patch added.

patch for magic-removal (includes all database backends)

03/02/06 12:04:31 changed by eugene@lazutkin.com

The patches are updated to include all 4 database backends. So far they worked on my sites (MySQL) and were reported by Ivan Sagalaev as working on Postgres. Nobody reported any negative experience. I assume we can roll them in at this point.

03/10/06 11:58:09 changed by eugene@lazutkin.com

Tickets #463, #900, and #1237 are closed as duplicates --- let's reduce a workload for developers.

03/28/06 11:39:55 changed by adrian

  • status changed from new to closed.
  • resolution set to fixed.

(In [2579]) Fixed #1442 -- Fixed multithreading problem with various database backends. Thanks, Eugene Lazutkin

03/28/06 11:40:20 changed by adrian

(In [2580]) Added missing file from [2579]. Refs #1442


Add/Change #1442 ([patch] Fixing multithreading problem with various database backends)




Change Properties
Action