mirror of
https://github.com/django/django.git
synced 2024-12-24 18:16:19 +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
|
||||
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 = []
|
||||
|
@ -47,14 +47,31 @@ class MysqlDebugWrapper:
|
||||
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,
|
||||
|
@ -9,7 +9,14 @@ import psycopg as Database
|
||||
|
||||
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 = []
|
||||
|
@ -24,7 +24,14 @@ def utf8rowFactory(cursor, row):
|
||||
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 = []
|
||||
|
Loading…
Reference in New Issue
Block a user