This is a snapshot of Indico's old Trac site. Any information contained herein is most probably outdated. Access our new GitHub site here.

Ticket #540: indico0.97_threading-2.patch

File indico0.97_threading-2.patch, 1.5 KB (added by pferreir, 5 years ago)

Patch for possible database threading issues (2)

  • indico/MaKaC/common/db.py

    diff --git a/indico/MaKaC/common/db.py b/indico/MaKaC/common/db.py
    index 00dc3dd..af0ebad 100644
    a b class DBMgr: 
    9292            cls._instance=DBMgr(*args, **kwargs) 
    9393        return cls._instance 
    9494 
     95    @staticmethod 
     96    def _getUniqueIdentifier(): 
     97        return threading._get_ident() 
     98 
    9599    def _getConnObject(self): 
    96         tid=threading._get_ident() 
    97         if self._conn.has_key(tid): 
    98             return self._conn[tid] 
    99         return None 
     100        tid = DBMgr._getUniqueIdentifier() 
     101        return self._conn[tid] 
    100102 
    101103    def _delConnObject(self): 
    102         tid=threading._get_ident() 
     104        tid = DBMgr._getUniqueIdentifier() 
    103105        del self._conn[tid] 
    104106 
    105107    def startRequest( self ): 
    106108        """Initialise the DB and starts a new transaction. 
    107109        """ 
    108110 
    109         conn = self._getConnObject() 
    110         if conn is None: 
    111             self._conn[threading._get_ident()]=self._db.open() 
    112             Logger.get('dbmgr').debug('Allocated connection for thread %s - table size is %s' % (threading._get_ident(), len(self._conn))) 
    113         else: 
    114             Logger.get('dbmgr').debug('Reused connection for thread %s - table size is %s' % (threading._get_ident(), len(self._conn))) 
     111        tid = DBMgr._getUniqueIdentifier() 
     112 
     113        self._conn[tid] = self._db.open() 
     114        Logger.get('dbmgr').debug('Allocated connection for %s - table size is %s' % (tid, len(self._conn))) 
    115115 
    116116    def endRequest( self, commit=True ): 
    117117        """Closes the DB and commits changes.