mirror of
https://github.com/django/django.git
synced 2025-05-05 22:47:32 +00:00
Fixed #1442 -- Fixed multithreading problem with various database backends. Thanks, Eugene Lazutkin
git-svn-id: http://code.djangoproject.com/svn/django/trunk@2579 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
3ff5b993d3
commit
67cbb5c248
@ -44,7 +44,14 @@ def variantToPython(variant, adType):
|
|||||||
return res
|
return res
|
||||||
Database.convertVariantToPython = variantToPython
|
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):
|
def __init__(self):
|
||||||
self.connection = None
|
self.connection = None
|
||||||
self.queries = []
|
self.queries = []
|
||||||
|
@ -47,14 +47,31 @@ class MysqlDebugWrapper:
|
|||||||
else:
|
else:
|
||||||
return getattr(self.cursor, attr)
|
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):
|
def __init__(self):
|
||||||
self.connection = None
|
self.connection = None
|
||||||
self.queries = []
|
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):
|
def cursor(self):
|
||||||
from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PORT, DATABASE_PASSWORD, DEBUG
|
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 = {
|
kwargs = {
|
||||||
'user': DATABASE_USER,
|
'user': DATABASE_USER,
|
||||||
'db': DATABASE_NAME,
|
'db': DATABASE_NAME,
|
||||||
|
@ -9,7 +9,14 @@ import psycopg as Database
|
|||||||
|
|
||||||
DatabaseError = Database.DatabaseError
|
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):
|
def __init__(self):
|
||||||
self.connection = None
|
self.connection = None
|
||||||
self.queries = []
|
self.queries = []
|
||||||
|
@ -24,7 +24,14 @@ def utf8rowFactory(cursor, row):
|
|||||||
return s
|
return s
|
||||||
return [utf8(r) for r in row]
|
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):
|
def __init__(self):
|
||||||
self.connection = None
|
self.connection = None
|
||||||
self.queries = []
|
self.queries = []
|
||||||
|
Loading…
x
Reference in New Issue
Block a user