Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed #1442 -- Fixed multithreading problem with various database bac…

…kends. Thanks, Eugene Lazutkin

git-svn-id: http://code.djangoproject.com/svn/django/trunk@2579 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
commit 67cbb5c248706bc101a6f3b9d65643423b5df1f8 1 parent 3ff5b99
@adrianholovaty adrianholovaty authored
View
9 django/core/db/backends/ado_mssql.py
@@ -44,7 +44,14 @@ def variantToPython(variant, adType):
return res
Database.convertVariantToPython = variantToPython
-class DatabaseWrapper:
+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):
def __init__(self):
self.connection = None
self.queries = []
View
21 django/core/db/backends/mysql.py
@@ -47,14 +47,31 @@ def __getattr__(self, attr):
else:
return getattr(self.cursor, attr)
-class DatabaseWrapper:
+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):
def __init__(self):
self.connection = None
self.queries = []
+ def _valid_connection(self):
+ if self.connection is not None:
+ try:
+ self.connection.ping()
+ return True
+ except DatabaseError:
+ self.connection.close()
+ self.connection = None
+ return False
+
def cursor(self):
from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PORT, DATABASE_PASSWORD, DEBUG
- if self.connection is None:
+ if not self._valid_connection():
kwargs = {
'user': DATABASE_USER,
'db': DATABASE_NAME,
View
9 django/core/db/backends/postgresql.py
@@ -9,7 +9,14 @@
DatabaseError = Database.DatabaseError
-class DatabaseWrapper:
+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):
def __init__(self):
self.connection = None
self.queries = []
View
9 django/core/db/backends/sqlite3.py
@@ -24,7 +24,14 @@ def utf8(s):
return s
return [utf8(r) for r in row]
-class DatabaseWrapper:
+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):
def __init__(self):
self.connection = None
self.queries = []
Please sign in to comment.
Something went wrong with that request. Please try again.