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.patch

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

Patch for possible database threading issues

  • indico/MaKaC/common/db.py

    diff --git a/indico/MaKaC/common/db.py b/indico/MaKaC/common/db.py
    index 00dc3dd..7729bfb 100644
    a b class DBMgr: 
    9292            cls._instance=DBMgr(*args, **kwargs) 
    9393        return cls._instance 
    9494 
     95    @staticmethod 
     96    def _getUniqueIdentifier(): 
     97        return "%s.%s" % (os.getpid(), threading._get_ident()) 
     98 
    9599    def _getConnObject(self): 
    96         tid=threading._get_ident() 
     100        tid = DBMgr._getUniqueIdentifier() 
    97101        if self._conn.has_key(tid): 
    98102            return self._conn[tid] 
    99103        return None 
    100104 
    101105    def _delConnObject(self): 
    102         tid=threading._get_ident() 
     106        tid = DBMgr._getUniqueIdentifier() 
    103107        del self._conn[tid] 
    104108 
    105109    def startRequest( self ): 
    106110        """Initialise the DB and starts a new transaction. 
    107111        """ 
    108112 
     113        tid = DBMgr._getUniqueIdentifier() 
    109114        conn = self._getConnObject() 
    110115        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))) 
     116            self._conn[tid] = self._db.open() 
     117            Logger.get('dbmgr').debug('Allocated connection for thread %s - table size is %s' % (tid, len(self._conn))) 
    113118        else: 
    114             Logger.get('dbmgr').debug('Reused connection for thread %s - table size is %s' % (threading._get_ident(), len(self._conn))) 
     119            Logger.get('dbmgr').debug('Reused connection for thread %s - table size is %s' % (tid, len(self._conn))) 
    115120 
    116121    def endRequest( self, commit=True ): 
    117122        """Closes the DB and commits changes.