Ticket #3504: selective_shutdown_at_thread_exit.patch
| File selective_shutdown_at_thread_exit.patch, 4.5 KB (added by cboos, 2 years ago) |
|---|
-
trac/env.py
181 181 """Return a database connection from the connection pool.""" 182 182 return DatabaseManager(self).get_connection() 183 183 184 def shutdown(self ):184 def shutdown(self, tid=None): 185 185 """Close the environment.""" 186 DatabaseManager(self).shutdown( )186 DatabaseManager(self).shutdown(tid) 187 187 188 188 def get_repository(self, authname=None): 189 189 """Return the version control repository configured for this -
trac/db/api.py
70 70 self._cnx_pool = ConnectionPool(5, connector, **args) 71 71 return self._cnx_pool.get_cnx() 72 72 73 def shutdown(self ):73 def shutdown(self, tid=None): 74 74 if self._cnx_pool: 75 self._cnx_pool.shutdown( )75 self._cnx_pool.shutdown(tid) 76 76 self._cnx_pool = None 77 77 78 78 def _get_connector(self): ### FIXME: Make it public? -
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 … … 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) … … 103 105 if num > 1: 104 106 self._active[tid][0] = num - 1 105 107 else: 106 del self._active[tid] 107 if cnx not in self._dormant: 108 cnx.rollback() 109 if cnx.poolable: 110 self._dormant.append(cnx) 111 else: 112 self._cursize -= 1 113 self._available.notify() 108 self._cleanup(tid) 114 109 finally: 115 110 self._available.release() 116 111 117 def shutdown(self): 112 def _cleanup(self, tid): 113 # Note: self._available *must* be acquired 114 if tid in self._active: 115 cnx = self._active.pop(tid)[1] 116 if cnx not in self._dormant: 117 cnx.rollback() 118 if cnx.poolable: 119 self._dormant.append(cnx) 120 else: 121 cnx.close() 122 self._cursize -= 1 123 self._available.notify() 124 125 def shutdown(self, tid=None): 118 126 self._available.acquire() 119 127 try: 120 for cnx in self._dormant: 121 cnx.cnx.close() 128 if tid: 129 cleanup_list = [tid] 130 else: 131 cleanup_list = self._active.keys() 132 for tid in cleanup_list: 133 self._cleanup(tid) 134 if not tid: 135 for cnx in self._dormant: 136 cnx.close() 122 137 finally: 123 138 self._available.release() -
trac/web/main.py
228 228 req.display(template, content_type or 'text/html') 229 229 else: 230 230 self._post_process_request(req) 231 except RequestDone: 232 raise 231 233 except: 232 234 err = sys.exc_info() 233 235 try: … … 348 350 349 351 req = Request(environ, start_response) 350 352 try: 351 db = env.get_db_cnx()352 353 try: 353 354 try: 354 355 dispatcher = RequestDispatcher(env) … … 357 358 pass 358 359 return req._response or [] 359 360 finally: 360 db.close() 361 if environ.get('wsgi.multithread', False): 362 env.shutdown(threading._get_ident()) 361 363 362 364 except HTTPException, e: 363 365 env.log.warn(e)
