o k`$@sddlZddlZddlmZddlmZddlmZmZddl m Z ddl m Z ddl mZGdd d eZGd d d eZGd d d eZeejddZeeZGdddeZdS)N) TracError)ConnectionWrapper) get_thread_id threading)time_now)exception_to_unicode)_c@seZdZdZdS) TimeoutErrorzjException raised by the connection pool when no connection has become available after a given timeout.N)__name__ __module__ __qualname____doc__rr./usr/lib/python3/dist-packages/trac/db/pool.pyr sr c@s*eZdZdZd ddZddZddZdS) PooledConnectionz]A database connection that can be pooled. When closed, it gets returned to the pool. NcCs$t|||||_||_||_dSN)r__init___pool_key_tid)selfpoolcnxkeytidlogrrrr&s zPooledConnection.__init__cCs4|jr|j}d|_d|_|j||j|jdSdSr)rrr _return_cnxrr)rrrrrclose,s zPooledConnection.closecCs |dSr)r)rrrr__del__3s zPooledConnection.__del__r)r r r r rrrrrrrr!s   rc@s<eZdZdZddZd ddZddZd d Zd d d ZdS)ConnectionPoolBackendz.A process-wide LRU-based connection pool. cCs8tt|_||_i|_g|_g|_g|_d|_ dS)Nr) r ConditionRLock _available_maxsize_activer _pool_key _pool_time_waiters)rmaxsizerrrr;s zConnectionPoolBackend.__init__Nc Csd}|d}t|}t}t}|jT||f|jvr*|j||f\}} | d7} n,|jdkr7|||||}|sT|jd7_|j|jd8_|||||}d} |ra|| f|j||f<Wdn1skwY| dkoxt |t } d} | r|\} }z| dkr| n| dkr| | dvr|j d i|}Wn5ty} z | } d}WYd} ~ n$d} ~ wty} z| } |r|jd| dd d}WYd} ~ nd} ~ ww|rt |t s| r|j|| f|j||f<Wdn1swYt|||||S| r-|j|j||f=Wdn 1swY| dkr-|||St | tr5| t|}td |d }t|| ) Nrrpingr)rcreatezException caught on %sT)exc_infoz:Unable to get database connection within %(time)d seconds.)timer)getstrrrr"r$r' _take_cnxwait isinstancetupler*rget_connectionr Exceptionerrorrget_cnxrr )r connectorkwargstimeoutrrrstartrnumdeferred exceptionopeerrmsgrrrr7Ds~          zConnectionPoolBackend.get_cnxcCs||jvr(|j|}|j||j||j|}t|dr&d|fS|St|jt|j|jkr7dSt|j|jkrU|jd}|jd|jdd|fSdS)zs