Ticket #3504: force_close_at_thread_exit.patch
| File force_close_at_thread_exit.patch, 2.6 KB (added by cboos, 2 years ago) |
|---|
-
trac/db/pool.py
19 19 except ImportError: 20 20 import dummy_threading as threading 21 21 threading._get_ident = lambda: 0 22 import sys 22 23 import time 23 24 24 25 from trac.db.util import ConnectionWrapper … … 38 39 ConnectionWrapper.__init__(self, cnx) 39 40 self._pool = pool 40 41 41 def close(self ):42 def close(self, thread_exits=False): 42 43 if self.cnx: 43 self._pool._return_cnx(self.cnx )44 self._pool._return_cnx(self.cnx, thread_exits) 44 45 self.cnx = None 45 46 46 47 def __del__(self): … … 87 88 'connection within %d seconds' \ 88 89 % timeout 89 90 else: 91 print>>sys.stderr, '[%d] wait for connection...' % tid 90 92 self._available.wait() 91 93 self._active[tid] = [1, cnx] 92 94 return PooledConnection(self, cnx) 93 95 finally: 94 96 self._available.release() 95 97 96 def _return_cnx(self, cnx ):98 def _return_cnx(self, cnx, thread_exits=False): 97 99 self._available.acquire() 98 100 try: 99 101 tid = threading._get_ident() 100 102 if tid in self._active: 101 103 num, cnx_ = self._active.get(tid) 102 104 assert cnx is cnx_ 103 if num > 1 :105 if num > 1 and not thread_exits: 104 106 self._active[tid][0] = num - 1 105 107 else: 106 108 del self._active[tid] … … 109 111 if cnx.poolable: 110 112 self._dormant.append(cnx) 111 113 else: 114 cnx.close() 112 115 self._cursize -= 1 113 116 self._available.notify() 114 117 finally: … … 118 121 self._available.acquire() 119 122 try: 120 123 for cnx in self._dormant: 121 cnx.cnx.close() 124 cnx.cnx.close() ### should be cnx.close() 122 125 finally: 123 126 self._available.release() -
trac/web/main.py
357 357 pass 358 358 return req._response or [] 359 359 finally: 360 db.close( )360 db.close(True) 361 361 362 362 except HTTPException, e: 363 363 env.log.warn(e)
