Edgewall Software

Ticket #8443: postgres-idle.patch

File postgres-idle.patch, 1.7 KB (added by mixedpuppy, 3 years ago)

postgres idle fix

  • pool.py

     
    132132    def _return_cnx(self, cnx, key, tid): 
    133133        self._available.acquire() 
    134134        try: 
    135             assert (tid, key) in self._active 
    136             cnx, num = self._active[(tid, key)] 
     135            #assert (tid, key) in self._active 
     136            # get the active connection and return it to the pool 
     137            cnx, num = self._active.get((tid, key), (None,0)) 
     138            if not cnx: return 
     139 
    137140            if num == 1: 
    138141                del self._active[(tid, key)] 
    139142                self._available.notify()  
     
    146149        finally: 
    147150            self._available.release() 
    148151 
    149     def shutdown(self, tid=None): 
     152    def _return_active_cnx(self, tid, connector, kwargs): 
     153        if not connector or not kwargs: 
     154            return 
     155        key = unicode(kwargs) 
     156        # shutdown is called at the end of every request, return the 
     157        # socket connection to the pool if there is one 
     158        cnx, num = self._active.get((tid, key), (None,0)) 
     159        if cnx: 
     160            self._active[(tid, key)] = (cnx, 1) 
     161            self._return_cnx(cnx, key, tid) 
     162 
     163    def shutdown(self, tid=None, connector=None, kwargs=None): 
    150164        """Close pooled connections not used in a while""" 
     165        self._return_active_cnx(tid, connector, kwargs) 
    151166        delay = 120 
    152167        if tid is None: 
    153168            delay = 0 
     
    176191        return _backend.get_cnx(self._connector, self._kwargs, timeout) 
    177192 
    178193    def shutdown(self, tid=None): 
    179         _backend.shutdown(tid) 
     194        _backend.shutdown(tid, self._connector, self._kwargs) 
    180195