ó ÃÌ4]c@sdZddlZddlZddlmZddlmZddlmZddlmZdd lm Z dd l m Z dd l m Z dd l m Z d efd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdefd„ƒYZdS(sPool implementation classes. iÿÿÿÿNi(t_ConnectionFairy(t_ConnectionRecord(tPooli(texc(tutil(tchop_traceback(tqueue(t threadingt QueuePoolcBseZdZddded„Zd„Zd„Zd„Zd„Zd „Z d „Z d „Z d „Z d „Z d„Zd„Zd„ZRS(sÝA :class:`.Pool` that imposes a limit on the number of open connections. :class:`.QueuePool` is the default pooling implementation used for all :class:`.Engine` objects, unless the SQLite dialect is in use. ii icKs]tj|||tj|d|ƒ|_d||_||_||_tj ƒ|_ dS(s$ Construct a QueuePool. :param creator: a callable function that returns a DB-API connection object, same as that of :paramref:`.Pool.creator`. :param pool_size: The size of the pool to be maintained, defaults to 5. This is the largest number of connections that will be kept persistently in the pool. Note that the pool begins with no connections; once this number of connections is requested, that number of connections will remain. ``pool_size`` can be set to 0 to indicate no size limit; to disable pooling, use a :class:`~sqlalchemy.pool.NullPool` instead. :param max_overflow: The maximum overflow size of the pool. When the number of checked-out connections reaches the size set in pool_size, additional connections will be returned up to this limit. When those additional connections are returned to the pool, they are disconnected and discarded. It follows then that the total number of simultaneous connections the pool will allow is pool_size + `max_overflow`, and the total number of "sleeping" connections the pool will allow is pool_size. `max_overflow` can be set to -1 to indicate no overflow limit; no limit will be placed on the total number of concurrent connections. Defaults to 10. :param timeout: The number of seconds to wait before giving up on returning a connection. Defaults to 30. :param use_lifo: use LIFO (last-in-first-out) when retrieving connections instead of FIFO (first-in-first-out). Using LIFO, a server-side timeout scheme can reduce the number of connections used during non-peak periods of use. When planning for server-side timeouts, ensure that a recycle or pre-ping strategy is in use to gracefully handle stale connections. .. versionadded:: 1.3 .. seealso:: :ref:`pool_use_lifo` :ref:`pool_disconnects` :param \**kw: Other keyword arguments including :paramref:`.Pool.recycle`, :paramref:`.Pool.echo`, :paramref:`.Pool.reset_on_return` and others are passed to the :class:`.Pool` constructor. tuse_lifoiN( Rt__init__t sqla_queuetQueuet_poolt _overflowt _max_overflowt_timeoutRtLockt_overflow_lock(tselftcreatort pool_sizet max_overflowttimeoutR tkw((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR #s =   cCsNy|jj|tƒWn0tjk rIz|jƒWd|jƒXnXdS(N(R tputtFalseR tFulltcloset _dec_overflow(Rtconn((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyt_do_return_conngs cCs|jdk}y2|o'|j|jk}|jj||jƒSWntjk rWnX|r´|j|jkr´|s€|jƒStj d|j ƒ|j ƒ|jfddƒ‚n|j ƒrøy|j ƒSWqtjƒ|jƒWdQXqXn |jƒSdS(NiÿÿÿÿsPQueuePool limit of size %d overflow %d reached, connection timed out, timeout %dtcodet3o7r(RRR tgetRR tEmptyt_do_getRt TimeoutErrortsizetoverflowt _inc_overflowt_create_connectionRt safe_reraiseR(Rt use_overflowtwait((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR$ps(    cCs_|jdkr"|jd7_tS|j.|j|jkrQ|jd7_tStSWdQXdS(Niÿÿÿÿi(RRtTrueRR(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR(s cCsI|jdkr"|jd8_tS|j|jd8_tSWdQXdS(Niÿÿÿÿi(RRR-R(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRšs  cCs}|jjdƒ|j|jd|jjd|jd|jd|jd|j d|j d|j d |j d |j d |jƒ S( NsPool recreatingRRRtrecycletechot logging_nametuse_threadlocaltreset_on_returnt _dispatchtdialect(tloggertinfot __class__t_creatorR tmaxsizeRRt_recycleR/t_orig_logging_namet_use_threadlocalt_reset_on_returntdispatcht_dialect(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pytrecreate¢s          cCsuxBtrDy |jjtƒ}|jƒWqtjk r@PqXqWd|jƒ|_|j j d|j ƒƒdS(NisPool disposed. %s( R-R R"RRR R#R&RR5R6tstatus(RR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pytdispose²s  cCs,d|jƒ|jƒ|jƒ|jƒfS(Ns_Pool size: %d Connections in pool: %d Current Overflow: %d Current Checked out connections: %d(R&t checkedinR't checkedout(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRA½s    cCs |jjS(N(R R9(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR&ÊscCs|jS(N(R(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRÍscCs |jjƒS(N(R tqsize(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRCÐscCs|jS(N(R(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR'ÓscCs|jj|jjƒ|jS(N(R R9RER(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRDÖs(t__name__t __module__t__doc__RR RR$R(RR@RBRAR&RRCR'RD(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRs" >       tNullPoolcBs;eZdZd„Zd„Zd„Zd„Zd„ZRS(sQA Pool which does not pool connections. Instead it literally opens and closes the underlying DB-API connection per each connection open/close. Reconnect-related functions such as ``recycle`` and connection invalidation are not supported by this Pool implementation, since no connections are held persistently. cCsdS(NRI((R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRAçscCs|jƒdS(N(R(RR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRêscCs |jƒS(N(R)(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR$íscCs_|jjdƒ|j|jd|jd|jd|jd|jd|jd|j d|j ƒS( NsPool recreatingR.R/R0R1R2R3R4( R5R6R7R8R:R/R;R<R=R>R?(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR@ðs       cCsdS(N((R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRBþs(RFRGRHRARR$R@RB(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRIÚs      tSingletonThreadPoolcBsbeZdZdd„Zd„Zd„Zd„Zd„Zd„Zd„Z d „Z d „Z RS( s¤A Pool that maintains one connection per thread. Maintains one connection per each thread, never moving a connection to a thread other than the one which it was created in. .. warning:: the :class:`.SingletonThreadPool` will call ``.close()`` on arbitrary connections that exist beyond the size setting of ``pool_size``, e.g. if more unique **thread identities** than what ``pool_size`` states are used. This cleanup is non-deterministic and not sensitive to whether or not the connections linked to those thread identities are currently in use. :class:`.SingletonThreadPool` may be improved in a future release, however in its current status it is generally used only for test scenarios using a SQLite ``:memory:`` database and is not recommended for production use. Options are the same as those of :class:`.Pool`, as well as: :param pool_size: The number of threads in which to maintain connections at once. Defaults to five. :class:`.SingletonThreadPool` is used by the SQLite dialect automatically when a memory-based database is used. See :ref:`sqlite_toplevel`. icKsJtj|||tjƒ|_tjƒ|_tƒ|_||_dS(N( RR Rtlocalt_connt_fairytsett _all_connsR&(RRRR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR !s  cCsh|jjdƒ|j|jd|jd|jd|jd|jd|jd|j d|j d |j ƒS( NsPool recreatingRR.R/R0R1R2R3R4( R5R6R7R8R&R:R/R;R<R=R>R?(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR@(s        cCsGx3|jD](}y|jƒWq tk r1q Xq W|jjƒdS(sDispose of this pool.N(RORt Exceptiontclear(RR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRB6s  cCs<x5t|jƒ|jkr7|jjƒ}|jƒqWdS(N(tlenROR&tpopR(Rtc((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyt_cleanupCscCsdt|ƒt|jƒfS(Ns"SingletonThreadPool id:%d size: %d(tidRRRO(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRAHs cCsdS(N((RR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRNscCs‹y|jjƒ}|r|SWntk r0nX|jƒ}tj|ƒ|j_t|jƒ|jkrw|j ƒn|jj |ƒ|S(N( RLtcurrenttAttributeErrorR)tweakreftrefRRROR&RUtadd(RRT((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR$Qs   cCsPy|jjƒ}Wntk r&nX|dk r=|jƒStj||jƒS(N(RMRWRXtNonet_checkout_existingRt _checkout(Rtrec((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pytconnect_s   cCs2y |j`Wntk r nX|j|ƒdS(N(RMRWRXR(Rtrecord((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyt _return_connks   ( RFRGRHR R@RBRURARR$R`Rb(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRJs       t StaticPoolcBsheZdZejd„ƒZejd„ƒZd„Zd„Zd„Z d„Z d„Z d„Z RS( s.A Pool of exactly one connection, used for all requests. Reconnect-related functions such as ``recycle`` and connection invalidation (which is also used to support auto-reconnect) are not currently supported by this Pool implementation but may be implemented in a future release. cCs |jƒS(N(R8(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRL~scCs t|ƒS(N(R(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyt connection‚scCsdS(NRc((R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRA†scCs,d|jkr(|jjƒd|_ndS(NRL(t__dict__RLRR\(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRB‰s cCsb|jjdƒ|jd|jd|jd|jd|jd|jd|jd|j d |j ƒS( NsPool recreatingRR.R1R2R/R0R3R4( R5R6R7R8R:R<R=R/R;R>R?(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR@Žs        cCs|jS(N(RL(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR)›scCsdS(N((RR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRžscCs|jS(N(Rd(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR$¡s( RFRGRHRtmemoized_propertyRLRdRARBR@R)RR$(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRcss     t AssertionPoolcBsDeZdZd„Zd„Zd„Zd„Zd„Zd„ZRS(sA :class:`.Pool` that allows at most one checked out connection at any given time. This will raise an exception if more than one connection is checked out at a time. Useful for debugging code that is using more connections than desired. cOsGd|_t|_|jdtƒ|_d|_tj |||ŽdS(Ntstore_traceback( R\RLRt _checked_outRSR-t_store_tracebackt_checkout_tracebackRR (RtargsR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR °s    cCsdS(NRg((R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRA·scCs:|jstdƒ‚nt|_||jks6t‚dS(Nsconnection is not checked out(RitAssertionErrorRRL(RR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRºs  cCs&t|_|jr"|jjƒndS(N(RRiRLR(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRBÀs  c CsD|jjdƒ|j|jd|jd|jd|jd|jƒS(NsPool recreatingR/R0R3R4(R5R6R7R8R/R;R>R?(R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR@Ås    cCs|jrJ|jr1ddjt|jƒƒ}nd}td|ƒ‚n|jse|jƒ|_nt|_|jr‰t j ƒ|_n|jS(Ns at: %sts!connection is already checked out( RiRktjoinRRmRLR)R-Rjt tracebackt format_stack(Rtsuffix((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyR$Ïs      ( RFRGRHR RARRBR@R$(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyRg¥s      (RHRpRYtbaseRRRRnRRRRR RRRIRJRcRg(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/pool/impl.pyt s  À(q2