#1442 closed defect (fixed)
[patch] Fixing multithreading problem with various database backends
Reported by: | Owned by: | Adrian Holovaty | |
---|---|---|---|
Component: | Database layer (models, ORM) | Version: | |
Severity: | normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
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 (4)
Change History (10)
by , 19 years ago
Attachment: | django.threading.patch added |
---|
comment:1 by , 19 years ago
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.
comment:2 by , 19 years ago
Summary: | [patch] multithreading problem with various backends → [patch] Fixing multithreading problem with various database backends |
---|
by , 19 years ago
Attachment: | django.threading.2.patch added |
---|
patch for trunk (includes all database backends)
by , 19 years ago
Attachment: | magic.threading.2.patch added |
---|
patch for magic-removal (includes all database backends)
comment:3 by , 19 years ago
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.
comment:4 by , 19 years ago
comment:5 by , 19 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
patch for Django trunk