Django

Code

Changeset 2579

Show
Ignore:
Timestamp:
03/28/06 11:39:53 (2 years ago)
Author:
adrian
Message:

Fixed #1442 -- Fixed multithreading problem with various database backends. Thanks, Eugene Lazutkin

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • django/trunk/django/core/db/backends/ado_mssql.py

    r2346 r2579  
    4545Database.convertVariantToPython = variantToPython 
    4646 
    47 class DatabaseWrapper: 
     47try: 
     48    # Only exists in python 2.4+ 
     49    from threading import local 
     50except ImportError: 
     51    # Import copy of _thread_local.py from python 2.4 
     52    from django.utils._threading_local import local 
     53 
     54class DatabaseWrapper(local): 
    4855    def __init__(self): 
    4956        self.connection = None 
  • django/trunk/django/core/db/backends/mysql.py

    r2450 r2579  
    4848            return getattr(self.cursor, attr) 
    4949 
    50 class DatabaseWrapper: 
     50try: 
     51    # Only exists in python 2.4+ 
     52    from threading import local 
     53except ImportError: 
     54    # Import copy of _thread_local.py from python 2.4 
     55    from django.utils._threading_local import local 
     56 
     57class DatabaseWrapper(local): 
    5158    def __init__(self): 
    5259        self.connection = None 
    5360        self.queries = [] 
    5461 
     62    def _valid_connection(self): 
     63        if self.connection is not None: 
     64            try: 
     65                self.connection.ping() 
     66                return True 
     67            except DatabaseError: 
     68                self.connection.close() 
     69                self.connection = None 
     70        return False 
     71 
    5572    def cursor(self): 
    5673        from django.conf.settings import DATABASE_USER, DATABASE_NAME, DATABASE_HOST, DATABASE_PORT, DATABASE_PASSWORD, DEBUG 
    57         if self.connection is None
     74        if not self._valid_connection()
    5875            kwargs = { 
    5976                'user': DATABASE_USER, 
  • django/trunk/django/core/db/backends/postgresql.py

    r2349 r2579  
    1010DatabaseError = Database.DatabaseError 
    1111 
    12 class DatabaseWrapper: 
     12try: 
     13    # Only exists in python 2.4+ 
     14    from threading import local 
     15except ImportError: 
     16    # Import copy of _thread_local.py from python 2.4 
     17    from django.utils._threading_local import local 
     18 
     19class DatabaseWrapper(local): 
    1320    def __init__(self): 
    1421        self.connection = None 
  • django/trunk/django/core/db/backends/sqlite3.py

    r2346 r2579  
    2525    return [utf8(r) for r in row] 
    2626 
    27 class DatabaseWrapper: 
     27try: 
     28    # Only exists in python 2.4+ 
     29    from threading import local 
     30except ImportError: 
     31    # Import copy of _thread_local.py from python 2.4 
     32    from django.utils._threading_local import local 
     33 
     34class DatabaseWrapper(local): 
    2835    def __init__(self): 
    2936        self.connection = None