[patch] Fixing multithreading problem with various database backends
|Reported by:||eugene@…||Owned by:||adrian|
|Component:||Database layer (models, ORM)||Version:|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
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.)
Change History (10)
comment:2 Changed 10 years ago by eugene@…
- Summary changed from [patch] multithreading problem with various backends to [patch] Fixing multithreading problem with various database backends